我尝试使用 jTable 选择一行并将行值存储到 topicId 中。然后,我使用刚刚获得的 topicId 从数据库中检索数据。这是我的代码。
    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 语句。我没有看到我的代码有什么问题,因为我没有看到任何数组。有人可以修复它吗?提前致谢。