This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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

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 );
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

Joined: Feb 05, 2001
Posts: 17276

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.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: ArrayIndexOutOfBounds Exception when calling TableModel . fireTableDataChanged
It's not a secret anymore!