javax.swing.plaf.synth.SynthContext.getPainter 处的 NullPointerException
我正在开发的一个 Java Swing 程序不断出现以下异常。它是随机发生的,并且很难重现。除了不触发按时操作事件之外,它似乎通常不会引起任何问题,但通常即使在出现此异常之后,事情也能正常工作。它的发生似乎没有一致性。有人有什么建议吗?我应该提到我们正在使用 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)
A Java Swing program I work on keeps getting the exception below. It happens at random times and is far from reproducible. It does not seem to usually cause any problem other than on time action events are not triggered but usually even after this exception things work fine. There seems to be no consistency to its happening. Any one have any advice? I should mention that we are using the 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有时在调用时会遇到同样的错误:
using Nimbus Look &感觉。就我而言,这样的调用是不必要的,因此我删除了该行。
I get the same error sometimes when invoking:
using Nimbus Look & Feel. In my case, such invocation was not necessary so I removed the line.
如果你在谷歌中搜索的话,这是一个相当流行的错误。
其中一个网站建议这样做:
This is quite a popular bug if you searched in Google.
One of the sites suggests this:
在尝试使用以下方法重新绘制 swing 组件后,我收到此错误:
其中
COMPONENT
是需要重新绘制的 swing 组件。我终于解决了这个问题,用这个替换上面的代码
I got this error after trying to repaint a swing component with the following method:
where
COMPONENT
is the swing component that needed to be repainted.I finally resolved this problem replacing the above code with this
我遇到了同样的问题并且能够修复它,如果您使用 SwingWorkers,我有两个建议。
1)在你的worker的doInBackground方法中尝试捕获任何运行时或未捕获的异常,这样你就可以验证你的方法没有在你认为退出之前退出。
2) 验证您没有在工作线程的属性更改事件之外更新任何 Swing 组件。请记住,所有 swing 组件都应该仅在事件线程中更新,而不是在工作线程中更新。
希望这有帮助。
I had the same problem and was able to fix it, I have two suggestions if you are using SwingWorkers.
1) In your worker's doInBackground method try to catch any Runtime or uncaught exceptions, so you can verify that your method is not exiting before you think it is.
2) Verify that you are not updating any Swing component outside the worker's property change events. Remember that all swing components should be updated only in the event thread not in the worker's thread.
Hope this helps.