问题
The Program:
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.
The Problem:
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.
The Code
This is how the user code is executed, the CompileActionListener calls the JavaCompiler:
method = CompileActionListener.getNewActor().getClass().getMethod("main"); method.invoke(CompileActionListener.getNewActor());
As far as I'm concerned the other code should not throw said execution (stack tree does not hint towards any of my own classes). Since this is a NPE it should be easy to trace back, but because of the lack of references towards my classes and the random time interval I'm clueless.
The stack trace
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)
Thank you in forward <3
回答1:
You can easily solve your problem with the powerful try
/ catch
.
来源:https://stackoverflow.com/questions/27745661/whats-causing-this-nullpointerexception-in-awt-eventqueue-0