String[] columnTitles = { "Flight #" , "Origin Airport" , "Destination Airport" , "Carrier #" , "Price" , "Day" , "Time" , "Duration" , "Available Seats" , "Select" }; I am trying to show the initial flight information with the check boxes in the last column for the user to select a particular flight for booking the seat. I am however getting this ArrayOutOfBoundsException java.lang.ArrayIndexOutOfBoundsException at suncertify.client.FlightInformationFrame$EditableTableModel.setValueAt(FlightInformationFrame.java:177) at javax.swing.JTable.setValueAt(JTable.java:1737) at suncertify.client.FlightInformationFrame.<init>(FlightInformationFrame.java:93) at suncertify.client.FlightInformationFrame.main(FlightInformationFrame.java:114) A portion of my code follows : String[] columnTitles = { "Flight #" , "Origin Airport" , "Destination Airport" , "Carrier #" , "Price" , "Day" , "Time" , "Duration" , "Available Seats" , "Select" }; for ( int i = 0; i < info.length; i++ ) { if ( info[i] != null ) { dataEntries[i] = info[i].getValues(); for ( int j = 0; j < len; j++ ) { if ( j < ( len - 1 ) ) table.setValueAt( dataEntries[i][j] , i, j ); else table.setValueAt( new Boolean(false) , i, j ); } // end of for } // end of if } // end of for clause
if ( j < ( len - 1 ) ) table.setValueAt( dataEntries[i][j] , i, j ); else table.setValueAt( new Boolean(false) , i, j );
which one of these setValueAt is line 177? try putting a System.out.println("Value of i is: " + i + ". Value of j is: " + j"); before each setValueAt. When you run it, see how far it gets, and add one to j, or maybe i? and you know which value is out of bounds. Mark [ March 07, 2002: Message edited by: Mark Spritzler ]
Hi Mark I have added the following SOP in my code. Please have a look at the output. if ( j < ( len - 1 ) ) { System.out.println("Setting String Value of i is: " + i + ". Value of j is: " + j); table.setValueAt( dataEntries[i][j] , i, j ); } else { System.out.println("Setting Boolean Value of i is: " + i + ". Value of j is: " + j); table.setValueAt( new Boolean(false) , i, j ); } j = 8 Setting String Value of i is: 0. Value of j is: 8 dataEntries[i][j] = 50 j = 9 Setting Boolean Value of i is: 0. Value of j is: 9 Thanks -- Ravindra
ravi janap
Ranch Hand
Joined: Nov 04, 2000
Posts: 389
posted
0
Sorry forgot to paste the rest of the output. j = 8 Setting String Value of i is: 0. Value of j is: 8 dataEntries[i][j] = 50 j = 9 Setting Boolean Value of i is: 0. Value of j is: 9 java.lang.ArrayIndexOutOfBoundsException at suncertify.client.FlightInformationFrame$EditableTableModel.setValueAt(FlightInformationFrame.java:182) at javax.swing.JTable.setValueAt(JTable.java:1737) at suncertify.client.FlightInformationFrame.<init>(FlightInformationFrame.java:97) at suncertify.client.FlightInformationFrame.main(FlightInformationFrame.java:119) Thanks -- Ravindra
Therefore the JTable doesn't go to 9. Well, it's partly true, I just really can't see where the problem is, except that there isn't a 9th column. But your column headers, do add up to 10 columns. Weird. Mark