lundi 23 avril 2018

How to porperly solve this : Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1

I am not sure how to set this properly without getting the error of Exception in thread "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);

    }                           

Aucun commentaire:

Enregistrer un commentaire