我嘗試選擇一行並使用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