Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java NullPointerException

8 views
Skip to first unread message

Lihua Pan

unread,
Mar 16, 2009, 11:32:14 AM3/16/09
to
I use java swing to design the GUI, and the error message appears from time to time (frequently when refresh or update the panel) on the command window even if the GUI works well. Anyone know the reason?
--------------------------------------------------------------------------------------------------------------------
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.paintRow(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI.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.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(Unknown 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)

Yair Altman

unread,
Mar 16, 2009, 12:18:20 PM3/16/09
to
"Lihua Pan" <plha...@gmx.de> wrote in message <gplrdu$e5r$1...@fred.mathworks.com>...

> I use java swing to design the GUI, and the error message appears from time to time (frequently when refresh or update the panel) on the command window even if the GUI works well. Anyone know the reason?


This happens when you're clicking on Swing elements faster than they can be rendered (for example, JTree nodes that need to expand/collapse as I suspect is the case in your case - right?). The fix is simply to use the EDT instead of accessing the JComponents directly from the main Matlab thread. If you have R2008+ then simply use the javaObjectEDT function after creating each Java object instance.

Yair Altman

Lihua Pan

unread,
Mar 16, 2009, 12:46:10 PM3/16/09
to
Thanks again for your reply. Does that mean if I use R2007a it is unavoidable?
"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message <gplu4b$f7c$1...@fred.mathworks.com>...

Yair Altman

unread,
Mar 16, 2009, 1:14:10 PM3/16/09
to
> Thanks again for your reply. Does that mean if I use R2007a it is unavoidable?

No - it means you'll need to use awkcreate/awtinvoke for all your GUI instances (my sympathies...). You can use programmatic pause() statements in strategic places as a poor-man's alternative but it will only reduce the problem, not dismiss it altogether as using the awt* functions. Or ask your users to click more slowly on your GUI... :-)

Yair

0 new messages