我正在尝试解决 arrayoutofbounds 异常 确切的错误是:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 Java Result: 1
public static void emptyBox() {
int , boxRow, boxColumn, i, j;
emptyBox = 0;
Row = 0;
Column = 0;
for (i = 0; (i < grid.length) && !(1 == emptyBox); i++) {
for (j = 0; (i < grid[i].length) && !(1 == emptyBox); j++) {
if (grid[i][j] == 0) {
emptyBox = 0;
Row = 0;
Column = 0;
}
}
}
}
I've tried a few attempts at debugging but no dice.
最佳答案
for (i = 0; (i < grid.length) && !(1 == emptyBoxFound); i++) {
for (j = 0; (i < grid[i].length) && !(1 == emptyBoxFound); j++) {
---------------------^
应该是j
而不是i
我不知道这是否是唯一的问题,但是......
关于java - 解决数组越界问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5267355/