I have a strange problem with my TableModel. Every time the Search button is pressed, it calls the following
String[][] dataRecords = flightServices.getFlights( currentCriteria ); flightTableModel.setRowData(dataRecords); and inside the TableModel.setRowData method it calls fireTableDataChanged();
This all works fine and the table updates after every search, unless I have selected a row in my table. The event handler for the table row selection retrieves the flight number using the following...
This returns the flightNumber no problem, but having called the flightTableModel.getValueAt() method, causes any further searches or reservations which (call the code above) to throw an ArrayIndexOutOfBoundsException. Specifically it is the call to fireTableDataChanged() Which throws the exception. If I take the flightTableModel.getValueAt() call out and replace it with a hard coded flight number, the system works fine ! has anyone got any ideas ?? Cheers, Dean
It is a difficult one. My code is exactly the same as yours and it works fine. I am not sure how getValueAt() is related to fireTableDataChanged(). Even if you have fireTableDataChanged() inside the getValueAt() method, it shouldn't throw any exception. Instead of having a row selection listener, try another JButton to show/book the flights. In that JButton action listener, try to read the selected row. [ May 22, 2002: Message edited by: Sai Prasad ]
dean tomlinson
Ranch Hand
Joined: Jan 31, 2002
Posts: 94
posted
0
thanks sai - your suggestion, of reading the flight number from a JButton action works like a dream. i have no idea why reading the value from the ListSelectionEvent casued me problems. ah well. thanks a lot.
No actually the problem is that you have values in the JTable and a row is selected. Say row #5, then you do another search update the table with say 3 rows, this fires the action, and tries to get the flight Number for row #5 but there is only 3 rows. Check this out. Jennifer had the same problem and I fixed it there. Mark