该计划:
一个简单的模拟器,用于学习Java的基础知识。用户可以在提供的编辑器中输入他自己的代码,该编辑器将玩家移动到一个字段中。此代码在单独的线程中执行。除了当前这个问题,程序运行正常,这个错误突然出现,之前没有出现过。
问题:
出于某种原因,在随机时间间隔内,玩家会抛出下面看到的异常。玩家执行的操作无关紧要,因为这也会在执行无限重复单个动作的随机时间后显示出来。每次执行该字段上的任何操作时都会抛出此错误,这意味着控制台日志会一遍又一遍地填充相同的错误消息。
守则
这是用户代码的执行方式,CompileActionListener调用JavaCompiler:
method = CompileActionListener.getNewActor().getClass().getMethod("main"); method.invoke(CompileActionListener.getNewActor());
就我而言,其他代码不应该抛出所述执行(堆栈树不会暗示我自己的任何类)。由于这是一个NPE,应该很容易追溯,但由于缺乏对我的班级和随机时间间隔的引用,我无能为力。
堆栈跟踪
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
答案 0 :(得分:-2)
您可以使用功能强大的try
/ catch
轻松解决问题。