gpt4 book ai didi

java - 是什么导致了 AWT-EventQueue-0 中的 NullPointerException?

转载 作者:行者123 更新时间:2023-11-29 09:32:06 24 4
gpt4 key购买 nike

程序:

A simple Simulator to learn the very basics of Java. The user can input his own code in a supplied editor, which moves players across a field. This code is executed in a separate thread. Aside from this current issue the program works fine, this error popped out of the blue and did not appear before.

问题:

For some reason and in random time intervals the player throws the exception seen below. It does not matter what action the player has performed, as this also shows up after a random time when executing an infinitely repeated single action. This error is thrown every time any action on the field is performed, which means that the console log is getting filled up with the same error message over and over.

代码

这是执行用户代码的方式,CompileActionListener 调用 JavaCompiler:

method = CompileActionListener.getNewActor().getClass().getMethod("main");
method.invoke(CompileActionListener.getNewActor());

就我而言,其他代码不应该抛出上述执行(堆栈树不暗示我自己的任何类)。由于这是一个 NPE,它应该很容易追溯,但由于缺乏对我的类(class)的引用和随机时间间隔,我一无所知。

堆栈跟踪

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.GlyphView.getBreakSpot(GlyphView.java:799)
at javax.swing.text.GlyphView.getBreakWeight(GlyphView.java:724)
at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:733)
at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:233)
at javax.swing.text.ParagraphView.calculateMinorAxisRequirements(ParagraphView.java:717)
at javax.swing.text.BoxView.checkRequests(BoxView.java:935)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:568)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:903)
at javax.swing.text.BoxView.checkRequests(BoxView.java:935)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:343)
at javax.swing.text.BoxView.layout(BoxView.java:708)
at javax.swing.text.BoxView.setSize(BoxView.java:397)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1722)
at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:912)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1659)
at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1332)
at java.awt.BorderLayout.layoutContainer(BorderLayout.java:821)
at java.awt.Container.layout(Container.java:1508)
at java.awt.Container.doLayout(Container.java:1497)
at java.awt.Container.validateTree(Container.java:1693)
at java.awt.Container.validateTree(Container.java:1702)
at java.awt.Container.validateTree(Container.java:1702)
at java.awt.Container.validate(Container.java:1628)
at javax.swing.RepaintManager$3.run(RepaintManager.java:704)
at javax.swing.RepaintManager$3.run(RepaintManager.java:702)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:701)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1719)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

谢谢转发<3

最佳答案

您可以使用强大的try/catch 轻松解决您的问题。

关于java - 是什么导致了 AWT-EventQueue-0 中的 NullPointerException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27745661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com