java - java中 "true"boolean 值的数组索引超出范围

标签 java for-loop jtable indexoutofboundsexception

请帮忙。我的代码中有一个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/

相关文章:

java - 使用 sendKeys() 在 Selenium 中上传文件不起作用

c++ - 减慢for循环的速度

java - 在 hibernate 中加载百万行

java - 无法使用 for 循环添加空格分隔的输入

c++ - 在c++中基于范围的for循环中使用引用作为控制变量

java - 获取jtable的单元格值

java - 使用 Glazed Lists 和 JXTable 进行表外列排序

java - 制作可点击的 JXTable 或 JTable

Java Swing 使用 JList 和 ArrayList<>

java - Android If 语句失败