javax.swing.plaf.synth.SynthContext.getPainter 处的 NullPointerException

发布于 2024-10-19 03:26:21 字数 2234 浏览 1 评论 0原文

我正在开发的一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

原野 2024-10-26 03:26:21

有时在调用时会遇到同样的错误:

 JComponent.updateUI() 

using Nimbus Look &感觉。就我而言,这样的调用是不必要的,因此我删除了该行。

I get the same error sometimes when invoking:

 JComponent.updateUI() 

using Nimbus Look & Feel. In my case, such invocation was not necessary so I removed the line.

独夜无伴 2024-10-26 03:26:21

如果你在谷歌中搜索的话,这是一个相当流行的错误。

其中一个网站建议这样做:

更换线路

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

与:

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

This is quite a popular bug if you searched in Google.

One of the sites suggests this:

replacing the line

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

with:

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

世俗缘 2024-10-26 03:26:21

在尝试使用以下方法重新绘制 swing 组件后,我收到此错误:

SwingUtilities.updateComponentTreeUI(COMPONENT); 

其中 COMPONENT 是需要重新绘制的 swing 组件。

我终于解决了这个问题,用这个替换上面的代码

COMPONENT.validate();
COMPONENT.repaint();

I got this error after trying to repaint a swing component with the following method:

SwingUtilities.updateComponentTreeUI(COMPONENT); 

where COMPONENT is the swing component that needed to be repainted.

I finally resolved this problem replacing the above code with this

COMPONENT.validate();
COMPONENT.repaint();
浮生未歇 2024-10-26 03:26:21

我遇到了同样的问题并且能够修复它,如果您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文