I'm trying to read in a text file which looks similar to this:
0000000000 0000100000 0001001000 0000100000 0000000000 Here is my code:
public static int[][] readBoard(String fileName) throws FileNotFoundException { File life = new File(fileName); Scanner s = new Scanner(life); int row = s.nextInt(); int columns = s.nextInt(); int [][] size = new int [row][columns]; for (int i=0; i <= row; i++) { String [] state = new String [columns]; String line = s.nextLine(); state = line.split(""); for (int j=0; i <= columns; i++) { size[i][j] = Integer.parseInt(state[j]); } } return size; } It keeps giving me this error. I think it's the Integer.parseInt(state[j]) that is giving me trouble, but I don't know why.
Exception in thread "main" java.lang.NumberFormatException: For input string: "" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68) at java.base/java.lang.Integer.parseInt(Integer.java:662) at java.base/java.lang.Integer.parseInt(Integer.java:770) at Project5.readBoard(Project5.java:33) at Project5.main(Project5.java:9) https://stackoverflow.com/questions/66700603/need-help-fixing-numberformatexception-error March 19, 2021 at 07:38AM
没有评论:
发表评论