wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes ArrayIndexOutOfBounds Exception when calling TableModel . fireTableDataChanged Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "ArrayIndexOutOfBounds Exception when calling TableModel . fireTableDataChanged" Watch "ArrayIndexOutOfBounds Exception when calling TableModel . fireTableDataChanged" New topic
Author

ArrayIndexOutOfBounds Exception when calling TableModel . fireTableDataChanged

dean tomlinson
Ranch Hand

Joined: Jan 31, 2002
Posts: 94
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...

String flightNumber = (String)flightTableModel.getValueAt( flightSearchResultsView.getFlightsTable().getSelectedRow(), 0 );

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
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
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
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ArrayIndexOutOfBounds Exception when calling TableModel . fireTableDataChanged
 
Similar Threads
question about booking a flight
JTable doesn't refresh after booking record
Overall Architecture Urgent!!!
JTable Delete row problem
mvc question