【发布时间】:2014-03-01 00:56:33
【问题描述】:
这段代码给了我一个 java.lang.NullPointerException 我不知道为什么。 确切的错误:
java.lang.NullPointerException
at com.bminus.ttp.controller.HUD.bind(HUD.java:35)
at de.lessvoid.nifty.screen.Screen.startScreen(Screen.java:210)
at de.lessvoid.nifty.Nifty.gotoScreenInternal(Nifty.java:678)
at de.lessvoid.nifty.Nifty.access$400(Nifty.java:77)
at de.lessvoid.nifty.Nifty$1.perform(Nifty.java:635)
at de.lessvoid.nifty.elements.EndOfFrameElementAction.perform(EndOfFrameElementAction.java:22)
at de.lessvoid.nifty.Nifty.executeEndOfFrameElementActions(Nifty.java:439)
at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:358)
at de.lessvoid.nifty.Nifty.update(Nifty.java:293)
at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:113)
at com.jme3.input.InputManager.processQueue(InputManager.java:819)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.bminus.ttp.ui.App.update(App.java:473)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
这是它指向的代码:
public void bind(Nifty theNifty, Screen theScreen)
{
this.nifty = theNifty;
this.screen = theScreen;
this.screen.addKeyboardInputHandler(new DefaultInputMapping(), this);
final ConsoleControl control = (ConsoleControl)this.nifty.createPopup("console-popup").findControl("console", ConsoleControl.class);
control.output("The Third Power");
control.output("Type 'help()' to get list of all available commands.");
control.addCommandHandler(new ConsoleCommandHandler()
{
public void execute(String theString)
{
try
{
Object result = HUD.SHELL.evaluate(String.format("TTP.%s", new Object[] { theString }));
if (result != null) {
if ((result instanceof Collection)) {
for (Object resultItems : (Collection)result) {
control.output(resultItems.toString());
}
} else {
control.output(result.toString());
}
}
}
catch (Exception exception)
{
control.output(String.format("Unknown command: %s", new Object[] { theString }));
}
}
});
SHELL.setVariable("TTP", this.consoleAPI);
}
更具体地说,就是这一行:
control.output("The Third Power");
我想知道的是为什么它给我一个 java.lang.NullPointerException 以及我如何修复这个错误以及如何确保它永远不会回来。如果有人需要更多关于我想要什么的信息,那就问吧。谢谢!
【问题讨论】:
-
你在 Eclipse 中尝试过调试模式吗?如果没有,您可能需要下载 Eclipse 集成开发环境 .. 它将为您提供相当多的故障排除(和编写)帮助!
-
这意味着您正在尝试对不存在的对象执行某些操作。也许它从未被实例化。
-
我正在使用 jMonkey Engine (NetBeans),我必须坚持下去。 @Erstwhilellll
-
@leigero 我该怎么做?
标签: java nullpointerexception jmonkeyengine