NullPointerException in javax.swing.plaf.synth.SynthContext.getPainter
The Java Swing program I am working on keeps getting the exception. This happens at random and is far from reproducible. It seems that this usually does not cause any problems other than timing events which do not fire, but usually even after this exception, everything works fine. There seems to be no sequence for his event. Anyone have any advice? I must mention that we are using nimbus LAF.
java.lang.NullPointerException
at javax.swing.plaf.synth.SynthContext.getPainter(SynthContext.java:181)
at javax.swing.plaf.synth.SynthPanelUI.update(SynthPanelUI.java:95)
at javax.swing.JComponent.paintComponent(JComponent.java:752)
at javax.swing.JComponent.paint(JComponent.java:1029)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at javax.swing.JComponent.paintChildren(JComponent.java:862)
at javax.swing.JComponent.paint(JComponent.java:1038)
at org.jdesktop.jxlayer.JXLayer.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5124)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:278)
at javax.swing.RepaintManager.paint(RepaintManager.java:1224)
at javax.swing.JComponent._paintImmediately(JComponent.java:5072)
at javax.swing.JComponent.paintImmediately(JComponent.java:4882)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:785)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:125)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
I sometimes throw the same error when calling:
JComponent.updateUI()
using Nimbus Look and Feel. In my case, such a call is not needed, so I removed the line.
This is a fairly common mistake if you google it.
One site offers the following:
replace string
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
from:
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
I got this error after trying to redraw the swing component in the following way:
SwingUtilities.updateComponentTreeUI(COMPONENT);
where COMPONENT
is the swing component to be repainted.
I finally solved this problem by replacing the above code with this
COMPONENT.validate();
COMPONENT.repaint();
I had the same problem and was able to fix it, I have two suggestions if you are using SwingWorkers.
1) In your working doInBackground method, try to catch any Runtime or uncaught exceptions so you can make sure your method is not terminating before you think about it.
2) Make sure you don't update any Swing component outside of worker property change events. Remember that all Swing components should only update on the event stream, not on the worker thread.
Hope this helps.