【发布时间】:2014-05-09 18:00:10
【问题描述】:
当用户单击按钮时,我试图从 JList 中删除选定的项目。
目前我有这样的事情:
private void clickActionPerformed(java.awt.event.ActionEvent evt) {
myList.remove(myList.getSelectedIndex());
}
当我单击按钮删除项目时,我收到此错误:
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
如何修复此错误,我的代码是否会删除多个项目?
【问题讨论】:
-
clickActionPerformed属于哪个类?您需要将ActionListener添加到您的按钮,然后覆盖actionPerformed。您确定在您向我们展示的地方获得了 index-out-of-bounds 异常吗?