请帮忙。我的代码中有一个indexArrayOutOfBounds。这是怎么回事? 编译器说错误发生在 if 语句处。
private void tableTest(){
int nRow = sampleTable.getRowCount();
int nCol = sampleTable.getColumnCount();
int counter = 0;
int j, i;
Object[][] tableData = new Object[nRow][nCol];
for (i = 0 ; i < nRow ; i++){
for (j = 3 ; j < nCol ; j++){
tableData[i][j] = sampleTable.getValueAt(i,j);
System.out.println(tableData[i][j]);
//if(counter)
// Arrays.deepToString(tableData[i][j]);
}
System.out.println("end");
if(tableData[i][j].equals(true)){
counter++;
System.out.print(counter);
}
}
}
最佳答案
一旦你的内部循环:for (j = 3 ; j < nCol ; j++){}
终止,值为j = nCol
。当您尝试访问元素 tableData[i][j]
时在你的if
在这种情况下,您正试图访问超出数组范围的内存位置。
关于java - java中 "true"boolean 值的数组索引超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23395982/