Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
java NullPointerException

Subject: java NullPointerException

From: Lihua Pan

Date: 16 Mar, 2009 15:32:14

Message: 1 of 4

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)

Subject: java NullPointerException

From: Yair Altman

Date: 16 Mar, 2009 16:18:20

Message: 2 of 4

"Lihua Pan" <plhalice@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

Subject: java NullPointerException

From: Lihua Pan

Date: 16 Mar, 2009 16:46:10

Message: 3 of 4

Thanks again for your reply. Does that mean if I use R2007a it is unavoidable?
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <gplu4b$f7c$1@fred.mathworks.com>...
> "Lihua Pan" <plhalice@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

Subject: java NullPointerException

From: Yair Altman

Date: 16 Mar, 2009 17:14:10

Message: 4 of 4

> 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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us