我正在try 绘制和初始化2d数组,当我的所有代码都在main方法中时,并没有错误,但我将代码拆分为方法,并且出现了索引错误.
这是我的方法:
public static void initializeTable(char[][] table ) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
table[i][j] = 'S'; //this is line 90 where the error occurs i think.
}
}
}
主要使用方法:
public class Cinema {
public static int row, column,x,y;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char[][] table = new char[row][column];
enterRowColumn();
initializeTable(table); //line 15
}
}
和错误消息:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at cinema.Cinema.initializeTable(Cinema.java:90)
at cinema.Cinema.main(Cinema.java:15)