Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 选择一个JTable行_Java_Jtable_Indexoutofboundsexception - Fatal编程技术网

Java 选择一个JTable行

Java 选择一个JTable行,java,jtable,indexoutofboundsexception,Java,Jtable,Indexoutofboundsexception,我试图通过单击从GUI中选择JTable中的行。我很好地选择了它,但当我试图删除某些内容时,我得到java.lang.ArrayIndexOutOfBoundsException:2>=1 if(row >= 0) { String id = table_1.getModel().getValueAt(row, 0).toString(); // here I got the error int idd = Integer.parseInt(id);

我试图通过单击从GUI中选择JTable中的行。我很好地选择了它,但当我试图删除某些内容时,我得到java.lang.ArrayIndexOutOfBoundsException:2>=1

    if(row >=  0) 
    {
    String id = table_1.getModel().getValueAt(row, 0).toString(); // here I got the error
    int idd = Integer.parseInt(id);
    Account account = bank.getAccounts().get(idd);
    bank.removeAccount(account);
    }

我该如何解决它呢?

将所有内容放入try-and-catch中,并确保变量行获得所需的值。我面临着一个类似的问题,我所要做的就是在不同的线程上处理数据,而AWT线程只能处理GUI元素。并且除了AWT线程之外,不要从任何线程更新GUI元素。如果您是从数据库中获取这些值,请使用不同的线程从数据库中删除,然后使用AWT线程相应地重新绘制GUI


解决这个问题的一个简单方法是,当您尝试多次执行删除操作时,IndexOutOfBounds异常是否会更改其值,例如,如果一次为2>=1,第二次为3>=2或其他,如果它不断更改,则需要更好地处理线程。希望这有帮助

什么决定变量行的值?它应该是这样的:
row=table_1.getSelectedRow()