我尝试选择一行并使用jTable将行值存储到topicId中。然后,我使用我刚才获得的topicId从数据库中检索数据。这是我的代码。ArrayIndexOutOfBoundsException错误消息
jTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
if (jTable.getValueAt(jTable.getSelectedRow(), 0) != null) {
int topicId = (Integer)jTable.getValueAt(jTable.getSelectedRow(), 0);}
eForumTopics topics = new eForumTopics(topicId);
topics.retrieveThread();
getJFrame().dispose();
eForumThreadContent myWindow = new eForumThreadContent(topicId);
myWindow.getJFrame().setVisible(true);
}
});
但是,我收到此错误消息。
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at kioskeForum.ui.eForumDiscussion$3.mouseClicked(eForumDiscussion.java:295)
295行是if语句。我没有看到我的代码有什么问题,因为我没有看到任何数组。有人可以修复它吗?提前致谢。
请学习Java命名约定并严格遵守 - _now_ – kleopatra