NullPointerException when trying to animate

Hello!

I am having some issues trying to play an animation. The animation was created in Blender and the model was imported from a blend file and converted into a j3o. The animation does work when I go to view the model’s animation within the JME3 IDE.

The issue that I am having is the following exception:

java.lang.NullPointerException
at com.lhsalliance.aquatic.core.Main.btn_Start(Main.java:374)
at com.lhsalliance.aquatic.core.Main$2.onAnalog(Main.java:270)
at com.jme3.input.InputManager.invokeAnalogs(InputManager.java:245)
at com.jme3.input.InputManager.invokeUpdateActions(InputManager.java:215)
at com.jme3.input.InputManager.update(InputManager.java:884)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
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)

It looks like the problem is that it cannot get the animation control and is made null.
To view the current state of my Main class, click here. To view all of my code in GitHub, click here.

Thanks for the help!

Hi there,

Your stacktrace tells me that the nullpointer occures at line 374

control.addListener(this);

Because the “this” is obviously not null, your control is null. Therefore your line before that

control = player.model.node.getControl(AnimControl.class);

You’re likely looking in the wrong place and would benefit from using this method http://hastebin.com/honidifubo.coffee

Also, be sure there isn’t 2 anim controls on your model by opening the .j3o in the scenecomposer.

Sometimes it will have 2, and you have to delete one.

For the record, even if ‘this’ were null, it would not cause an NPE on that line. Therefore, control is the only thing that could be null. ie: it works even if you were passing something else that might be null. (You’d get an NPE but in a different place.)