【问题标题】:java - jtable getvalue method not workingjava - jtable getvalue 方法不起作用
【发布时间】:2018-07-30 20:12:45
【问题描述】:

我刚刚在 java 中创建了一个简单的表,我正在尝试获取行内的数据

ArrayList<Object> s = new ArrayList<Object>();

private void get_valuesActionPerformed(java.awt.event.ActionEvent evt)                                           
{                                               
    for (int i = 1; i <= mod.getRowCount(); i++)
    {
        for (int j = 1; j <= mod.getColumnCount(); j++)
        {
           System.out.println(mod.getValueAt(i,j));
           //System.out.println("row= "+i+"column= "+j);
        }
    }
}

当我计算和打印行和列时,它可以工作,

但是当使用getValue()method 时,会出现以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 &gt;= 1

我有列(名称,密码),为什么会出现这个异常?,我应该怎么做才能获取数据?

【问题讨论】:

    标签: java jtable indexoutofboundsexception


    【解决方案1】:

    在 java 中,与大多数编程语言一样,您从 0 开始计数,而不是 1。

    这意味着您应该将 for 循环更改为:

    for (int i = 0; i <= mod.getRowCount() - 1; i++)
    
    for (int j = 0; j <= mod.getColumnCount() - 1; j++)
    

    【讨论】:

    • 或者只使用 for (int i = 0; i
    • 很高兴为您提供帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    相关资源
    最近更新 更多