The following error occurs if I double click in a JTable cell which is editable and without changing the value move (by clicking) to another cell.
The error doesn't occur within my code (it occurs in a sun class, probably as a result of the parameter sent from my code), and thus I cant' view the function in which this error occurs.
Its really got me stumped, so any advice appreciated!
java.lang.NullPointerException at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.adjustFocusAndSelection(Unknown Source) at javax.swing.plaf.basic.BasicTableUI$MouseInputHandler.mousePressed(Unknown Source) at java.awt.AWTEventMulticaster.mousePressed(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(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)
Actually, you do have the source for that class, but you'll have to do some detective work to figure out which line could have caused an NPE.However, in skimming it I see method calls on only three references: the JTable table, the MouseEvent e, and the CellEditor editor. I can't imagine the table being set to null -- this is the object the PLF handler is handling. It also seems highly unlikely that the MouseEvent is passed in null without having triggered an NPE earlier. And the editor is tested for null before calling one of its methods.
Oh, I should point out that the above code is for JDK 1.4.2. Heh, that must be it. Anyway, as I just posted in another thread a few minutes ago, take advantage of having the Java sources. Even when you don't have the exact line number you can usually narrow it down.
On a side note, sometimes reading the Java source code can be very entertaining. I especially like this programming gem from the above method:I'll never tire of finding "<boolean-expr> ? true : false". It's right up there with "if ( <boolean-expr> == true )".
Joined: Nov 11, 2004
Well i'm using Eclipse and that was the entire error message which appeared in the console.
Can you advise me where to find the Java sources? I have tried adding the source location but haven't had any success, and im not sure what .jar to add.
Also any advice on the error? Oh and yes it is Java 1.4.2.
Joined: Aug 07, 2003
The sources typically come bundled with the JDK. Look in the root of the JDK directory for "src.zip" and unpack it. If you don't find it, you can download it from java.sun.com as they sometimes omit it from the JDK installer.
Sadly, I don't see anything that could be causing the issue. Can you provide some more details? What cell editor are you using? Is it 100% reproducible, and does it only occur in that specific case?
Originally posted by Mark Spritzler: Actually it isn't the entire stack trace because based on what you posted something out of the blue called the EventDispatchThread.
Actually, I tihnk it is a complete stack trace. If I remember correctly, when you create and start a new Thread, it's stack starts with Thread.run().
Joined: Nov 11, 2004
I'm using the default cell editor, no special implementation.
Basically the error occurs every time the following sequence of actions is taken..
Double click in a cell (to put it in editing mode) then without changing the value, moving to another cell. OR unchecking or checking the boolean checkbox generates the same error.
I've never used JTables before and I only have two days to remove this error, otherwise i'll just have to surround the whole program with a catch statement and output it to a file.
Any further ideas?
Joined: Aug 07, 2003
Checkbox? Do you mean when you have a column that uses a JCheckBox as its editor component (the value's type is Boolean)? That's the only reasonable-sounding thing to me, but that seems doubly-odd that other components used for editing (text field, list, etc) work fine.
Even though the stack trace makes no mention of it, my gut is telling me the problem is ultimately being caused by the model while the exception is actually triggered elsewhere. In other words, the model does something naughty if the value hasn't been edited or a Boolean is altered.
I have a few recommendations:
Search Sun's Java forums and especially the bug-tracking database. Maybe you'll get lucky and someone else has run into it before.
Post this in the Swing forum to catch any experts there that don't also read this forum. To be nice, include a link back to this message stating your reason for cross-posting (as it's generally frowned upon) so people can get as much info as possible.
Run it inside an IDE and inspect the JTable and related objects. See if you can spot anything.
Try using a different Swing look and feel.
Try a simple test by replacing the model you're using with a DefaultTableModel with a few rows and columns, one including a Boolean. If this causes the exception, that would imply that the JDK itself has a serious problem. This seems doubtful as JDK 1.4.2 has been out for a long time; it should have been caught by now.
If you can package it up with all necessary libraries such that I'd be able to run it locally, I'd be willing to poke at it a bit. Obviously, this may not be an option if there are unresolvable external dependencies (e.g. a database) or your company isn't cool with it. But if you can, send it to the email in my profile (second icon from the left after the posting date on any of my messages). Gmail should be able to handle it.