我试图在Java中获取一行JTable的值,即行的值 来自数据库:
table.getSelectionModel().addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent event)
{
//eTime.setText(table.getValueAt(table.getSelectedRow(), 0).toString());
// eName.setText(table.getValueAt(table.getSelectedRow(), 1).toString());
// eValue.setText(table.getValueAt(table.getSelectedRow(), 2).toString());
// cName.setText(table.getValueAt(table.getSelectedRow(), 3).toString());
// cModel.setText(table.getValueAt(table.getSelectedRow(), 4).toString());
try{
System.out.println(table.getValueAt(table.getSelectedRow(), 3).toString());
}catch(Exception g)
{ System.out.println(g);
}}
});
当我按下该表的一行时,我得到以下异常:java.lang.ArrayIndexOutOfBoundsException: -1
我在这里做错了什么?