Sin*_*ngh 0 java nullpointerexception
我正在阅读代表迷宫图案的文本文件.每行读入1d char数组,然后将一个1d数组插入到2d char数组中.
在以下方法中获取nullpointerexception
line = (input.readLine()).toCharArray();
Run Code Online (Sandbox Code Playgroud)
private void fillArrayFromFile() throws IOException
{
BufferedReader input = new BufferedReader(new FileReader("maze.txt"));
//Read the first two lines of the text file and determine the x and y length of the 2d array
mazeArray = new char[Integer.parseInt(input.readLine())][Integer.parseInt(input.readLine())];
char [] line = new char[10];
//Add each line of input to mazeArray
for (int x = 0; x < mazeArray[0].length; x++)
{
line = (input.readLine()).toCharArray();
System.out.print(x + " : ");
System.out.println(line);
mazeArray[x] = line;
}
}
Run Code Online (Sandbox Code Playgroud)