Jmonkey 空指针异常
Jmonkey NullPointerException
这是我用模型加载节点然后附加动画控件的代码。我收到 NullPointerException,因为它说我的 AnimControl 为空。
我的动画控件 class 在 Models/stickman。blend/Armature/Cube
Node model = (Node)assetManager.loadModel("Models/stickman.j3o");
control = model.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim("jump");
model.scale(0.25f);
model.addControl(physicsCharacter);
getPhysicsSpace().add(physicsCharacter);
rootNode.attachChild(model);
如何摆脱这个 nullpointerexception 或将 AnimControl class 移出子目录使其不为空?谢谢
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:96)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)
NullPointerException 尽可能清楚地告诉您变量 control
为空。这反过来意味着 model.getControl(AnimControl.class);
返回了 null。 javadoc tells you it will do this如果没有控件类型AnimControl.class
我想,看着the tutorial, that you must attach your Node to the rootNode. From this page
Every JME3 application has a rootNode: Your game automatically inherits the rootNode object from SimpleApplication.
所以,只要你的classextends SimpleApplication
你只需要添加
rootNode.attachChild(model);
紧接着
Node model = (Node)assetManager.loadModel("Models/stickman.j3o");
似乎此附件会自动将您的模型与控件相关联 - 如 animation beginners tutorial
中的这段代码所示
player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
这是我用模型加载节点然后附加动画控件的代码。我收到 NullPointerException,因为它说我的 AnimControl 为空。
我的动画控件 class 在 Models/stickman。blend/Armature/Cube
Node model = (Node)assetManager.loadModel("Models/stickman.j3o");
control = model.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim("jump");
model.scale(0.25f);
model.addControl(physicsCharacter);
getPhysicsSpace().add(physicsCharacter);
rootNode.attachChild(model);
如何摆脱这个 nullpointerexception 或将 AnimControl class 移出子目录使其不为空?谢谢
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:96)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)
NullPointerException 尽可能清楚地告诉您变量 control
为空。这反过来意味着 model.getControl(AnimControl.class);
返回了 null。 javadoc tells you it will do this如果没有控件类型AnimControl.class
我想,看着the tutorial, that you must attach your Node to the rootNode. From this page
Every JME3 application has a rootNode: Your game automatically inherits the rootNode object from SimpleApplication.
所以,只要你的classextends SimpleApplication
你只需要添加
rootNode.attachChild(model);
紧接着
Node model = (Node)assetManager.loadModel("Models/stickman.j3o");
似乎此附件会自动将您的模型与控件相关联 - 如 animation beginners tutorial
中的这段代码所示player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);