JMenu 中的异常

发布于 2024-10-21 17:32:24 字数 2503 浏览 6 评论 0原文

我用Java开发了一个应用程序。

它出现的问题是,第一次单击后,如果用户再次单击菜单,则会发生以下异常。

由于它显示源未知,所以我不可能调试它...

任何人都可以帮我解决这个问题吗?


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at sun.font.FontDesignMetrics$MetricsKey.init(Unknown Source)
        at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
        at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
        at javax.swing.JComponent.getFontMetrics(Unknown Source)
        at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
        at javax.swing.plaf.synth.SynthMenuItemUI.paint(Unknown Source)
        at javax.swing.plaf.synth.SynthMenuUI.paint(Unknown Source)
        at javax.swing.plaf.synth.SynthMenuUI.update(Unknown Source)
        at javax.swing.JComponent.paintComponent(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JLayeredPane.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(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.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(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.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(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)

I've developed an application in Java..

The problem occuring with it is that after first click, if the user clicks on menu again then following exception occurs..

Since it is showing that source is unknown, it is not possible for me to debug it...

Can anyone help me with this ??


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at sun.font.FontDesignMetrics$MetricsKey.init(Unknown Source)
        at sun.font.FontDesignMetrics.getMetrics(Unknown Source)
        at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
        at javax.swing.JComponent.getFontMetrics(Unknown Source)
        at sun.swing.SwingUtilities2.getFontMetrics(Unknown Source)
        at javax.swing.plaf.synth.SynthMenuItemUI.paint(Unknown Source)
        at javax.swing.plaf.synth.SynthMenuUI.paint(Unknown Source)
        at javax.swing.plaf.synth.SynthMenuUI.update(Unknown Source)
        at javax.swing.JComponent.paintComponent(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JLayeredPane.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(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.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.seqPaintDirtyRegions(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.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

怪我入戏太深 2024-10-28 17:32:25

我假设第一次单击是显示菜单和菜单项的单击。如果用户然后单击菜单项,并且出现异常,我敢打赌您还没有完全实例化与菜单关联的某些菜单项组件。

希望这有帮助。

约翰·多纳

I'll assume that the first click is the one that displays the menu and the menu items. If the user then clicks on a menu item, and you get an exception, I would bet that you have not fully instantiated some of the menu item components associated with the menu.

Hope this helps.

John Doner

缪败 2024-10-28 17:32:25
 at sun.font.FontDesignMetrics$MetricsKey.init(Unknown Source)

检查字体的实例化。您需要在某处使用 new Font(name, ...)

 at sun.font.FontDesignMetrics$MetricsKey.init(Unknown Source)

Check the instantiation of your fonts. You need to use new Font(name, ...) somewhere.

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