Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI update error

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a written a solution to the URLyBird project.

Sometimes I am getting a strange excepetion.

I have 4 versions of the program running simultaniously using RMI to connect to the database. As I delete records with one screen it updates the other screens and removes the record.

Sometimes I get an ArrayIndexOutOfBoundsException on only one of the screens. Which doesn't make sense to me as It should happen to all or none as they are running the same code.

The problem I am having debugging this is when the Exception dumps to screen it says (Unknown Source)

Also where I start the program I have a try block catching the exception but for some reason it gets by passed....I'm guessing because of the Unkown Source

By the way I am implementing the Observer patter to update the screens when the database changes

Does anyone have any ideas?

Thanks
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see my reply to your other question pertaining to this problem.
Splitting your actual question into several posts in different forums doesn't make it easier for people to help you.

Unless you examine the entire stacktrace you're never going to find what is happening. The unknown source message in this is irrelevant, as it is in a library you have no control over (Sun is nice enough to ship the source to the JDK, many other companies don't so never rely on it).
As long as you didn't explicitly compile with flags to not include debug info you will have line numbers for your own classes, which is where the real error is.
Most likely from what I read here and in the other thread combined you are having a problem with your thread synchronisation.
Maybe one of the tables occassionally starts to update itself too soon.
It gets the rowcount when the record isn't yet removed from your collection, but by the time it is iterating over the collection the record has been removed so the collection is now shorter than the iteration loop thinks it is, causing an ArrayIndexOutOfBoundsException to be thrown on the last iteration through the loop.
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting twice...I didn't know how many people read both forums and though the question might be better answered in the Advance.

Thanks for your help.

The entire message is
C:\URLyBird>java URLyBird
java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableColumnModel.getColumn(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknow
n Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)




The java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
part changes all the time. Sometimes it's 5>=4, 3>=2.

I'll check out the synchronized parts now

Thanks
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I view the entire stacktrace?
I can't catch the exception so I can't print the stacktrace

also I am compiling with the -g generate all debug information option
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just run the program in stand alone mode with several instances of the GUI. They all continually update fine and the error doesn't occur.

I think it must have something to do with RMI then.

Any ideas?
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have now implemented the Proxy pattern.

The GUI talks to a proxy who talks to the database.
The proxy only talks to the database in sync blocks.
So now I'm pretty sertain it is not a sync error.

I even overloaded ever public method in JTable trying to catch the exception.
i.e.
this.table = new JTable() {
public void updateUI() {
try {
super.updateUI();
} catch (Exception e) {
System.out.println("Error " + e);
}
}
}

I'm having trouble thinking of anything else.
Any help please?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you confirmed my suspicion that there's a problem with your thread safety and that you're getting the number of records you're to iterate over outside synchronised code causing in some instances that number to be 1 lower than the number of elements in the iterator (and thus the iterator to throw the exception you get on trying to read past the last element in your dataset).
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no implemented the MVC pattern.
The model updates before the GUI

this is the code that blows up, sometimes

1- DefaultTableModel DM = new DefaultTableModel();
2- DM.setDataVector(records, columnNames);
3- DM.getColumnCount() );
4- System.out.println("DM " + DM.getRowCount() + " " + DM.getColumnCount() );
5- this.table.setModel(DM);

It is always on line 5

line 4 prints the same on every instance of the program.
So doesn't that mean the data is ok?

Also this is run in synch block that locks table

This is driving me nuts!

Thanks for your help
 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have located the problem line of code.
It is this line
tableChanged(new TableModelEvent(dataModel, TableModelEvent.HEADER_ROW));

I don't understand why this is happening and so inconsistently.
Is it a bug with Java?



protected class MyTable extends JTable {

public void setModel(TableModel dataModel) {

System.out.println("Start setModel");
try {
this.dataModel = dataModel;
System.out.println("BANG");
tableChanged(new TableModelEvent(dataModel, TableModelEvent.HEADER_ROW));

} catch (Exception e) {
System.out.println("ERROR");
}
System.out.println("Finished setModel");
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic