Hey guys, so I'm trying to read from a .txt file (which is written in a specific way) and then save some integers in a 2-dimensional array. The .txt file is written like this:
5
4 5 3 2 1
1 3 2 4 5
2 5 3 4 1
1 4 3 2 5
4 3 2 1 5
My code is this:
int[][] protimiseisA = null; in = new BufferedReader(new FileReader("prefsA.txt")); //reading the first number String str = in.readLine(); //saving it for use later int sum = Integer.parseInt(str); //reading the empty line and discarding it str = in.readLine(); //gist of the code, read the next five lines and save the integers in the array for (int x = 0; x < sum; x++) { str = in.readLine(); String[] str2 = str.split("\\s+"); for (int y = 0; y < sum; y++) { protimiseisA[x][y] = Integer.parseInt(str2[y]); } }
Of course that's only part of the code but that's where the problem is imo, since it throws a NullPointerException at the line "protimiseisA[x][y] = Integer.parseInt(str2[y]);"
Any help would be greatly appreciated!