【发布时间】:2017-04-03 05:33:26
【问题描述】:
抱歉,这个问题不能真正应用于其他人。我已经看了几个小时了,我仍然看不到它。它一定非常简单,但我找不到我试图访问不存在的东西的地方。我得到了一个
遍历 9x9 网格时出现 ArrayIndexOutOfBoundsException。
public ArrayList<Grid> next9Grids()
{
ArrayList<Grid> next9 = new ArrayList<Grid>();//list of new Grids
for(int i = 0; i < values.length; i++){
for(int j = 0; i < values[i].length; j++){
if (values[i][j] == 0){//if empty
for(int next = 1; next <= 9; next++){
Grid temp9 = new Grid(this);//need to make another grid for each #
temp9.values[i][j] = next; // changes value of empty space to 1->9
next9.add(temp9); //add grid to arrayList
}
return next9;
}
}
}
return null;
}
线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 9 在数独.Grid.next9Grids(Grid.java:112) 在 数独.Solver.solveRecurse(Solver.java:54) 在 数独.Solver.solveRecurse(Solver.java:56) 在 数独.Solver.solveRecurse(Solver.java:56)
这是错误的来源。(Grid.java:112)是---->if(values[i][j] ==0){
另一个问题是为什么在第 112 行访问第二个 for 循环首先迭代而不是第二个 for 循环的内容时会在第 112 行引发错误?
任何事情都非常感谢。感谢您的反馈。
【问题讨论】:
-
i < values[i].length应该是j < values[i].length
标签: java indexoutofboundsexception