I'm making a file that fills a grid of characters, but it doesn't detect the file.
String map; String texture; Scanner asdf; int rows; int cols; char Map[][]; public Map() { } public Map(String map) { System.out.println("Finding map...."); loadGrid(map); System.out.println("Map Loaded"); if (texture == "" || texture == null) { System.out.println("Texture not found..."); } else System.out.println("Texture Loaded."); } //loads the grid public void loadGrid(String map) { asdf = new Scanner(map); rows = asdf.nextInt(); cols = asdf.nextInt(); Map = new char[rows][cols]; for (int i = 0; i < rows; i++) { String a = asdf.nextLine(); for (int j = 0; j < cols; j++) { Map[i][j]=a.charAt(j); } } } //prints the characters making up the map public void print() { for (int i = 0; i < Map.length; i++) { for (int j = 0; j < Map[i].length; j++) { System.out.print(Map[i][j] + " "); } System.out.println(""); } }
And it keeps giving me this error:
If anyone knows what my problem is I'd greatly appreciate the help... :/run:
Map initialized
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at xavi.Map.loadGrid(Map.java:49)
at xavi.Xavi.main(Xavi.java:17)
Java Result: 1