【发布时间】:2018-04-23 15:34:33
【问题描述】:
我不确定如何正确设置它而不会出现
的错误线程“AWT-EventQueue-0”中的异常 java.lang.ArrayIndexOutOfBoundsException: -1
int row=table_1.getSelectedRow();
int column=4;
// If I put it here I get the error and won't run at all the if below
// String tableRoCol = table_1.getModel().getValueAt(row, column).toString();
if (row==-1 ) {
JOptionPane.showMessageDialog(null, "Please select a room to continue!");
}
// If I put it here I get the error after it run
// String tableRoCol = table_1.getModel().getValueAt(row, column).toString();
String tableRoCol = table_1.getModel().getValueAt(row, column).toString();
if ( tableRoCol.equals("Booked")) {
JOptionPane.showMessageDialog(null, "Please select a room that is Free to continue!");
} else {
column =3;
String tableColRoom = table_1.getModel().getValueAt(row, column).toString();
System.out.println("THE room ID IS :"+tableColRoom);
}
【问题讨论】:
标签: java if-statement