你的
String maze[][]
是
null
static Maze maze = new Maze(null,0,0,0,0); // notice that null
你试图在通话时赋予它价值
mazeBuild()
. 您应该初始化它或传递数组,而不是
. 你可以在
public static void mazeBuild() {
maze.maze = new String[maze.rows][maze.columns]; // <-- this one!
for(int x = 0; x < maze.rows; x++) { // <-- this loop tries to
for(int y = 0; y < maze.columns; y++) { // put values in your
maze.maze[x][y]= "."; // maze.maze (2D String array)
System.out.print(maze.maze[x][y]);
}
System.out.println();
}
您也可以这样做,以交换我添加的代码行。
String[][] mazeArray = new String[maze.rows][maze.columns];
maze = new Maze(mazeArray, maze.rows, maze.columns, 0, 0);