Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] java.lang.Null

I would like to have help with a error I’m are currently having for the Jmonkey Engine 3 and possibly help others if they are getting the same or similar message. I keep getting this error when I run/build the project, I’ve had problems before during my last post, on which I have not solved so I added this line of Code : control = player.getControl(AnimControl.class);
To remedy the problem but it has only created another one and possibly more.

I have also renamed the node in the scene composer from the animated model, I am trying to load from “Cube-Ogre mesh” to “player” to see if that will change anything and on the AnimControl in the scene composer of the Animated Model. I have tried to change the Animation Control form the default “Null” to their Animations but they do not save.

Now I get this error
“Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Test1.simpleInitApp(Test1.java:63)
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)”

Let’s solve this once and for all!

But when I put the model in the scene composer and go into AnimControl the animations when I play them work.

The whole Code

package mygame;

import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.light.PointLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**

  • test

  • @author
    /
    public class Test1 extends SimpleApplication
    implements AnimEventListener {
    private AnimChannel channel;
    private AnimControl control;
    Node player;
    /
    *
    *

    • @param args
      */
      public static void main(String[] args) {
      Test1 app = new Test1();
      app.start();
      }

    /**
    *
    */
    @Override
    public void simpleInitApp() {
    initKeys();

    Spatial Scene = assetManager.loadModel(“Models/Hotelroom/Hotelroom.blend”);
    rootnode.attachChild(Scene);

    DirectionalLight sun = new DirectionalLight();
    sun.setDirection((new Vector3f(-.1f, -.1f, -.1f)).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.attachChild(Scene);
    rootNode.addLight(sun);//if you comment this out,all is darkness Yes Cracked it!
    player = (Node) assetManager.loadModel(“Models/Main Chr/Cube.mesh.j3o”);
    player.setLocalTranslation(20f, 1100f, 90f);
    player.scale(1.60f);
    rootnode.attachChild(player);
    control = player.getControl(AnimControl.class);
    player.getChild(“player”).getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim(“Idle”);

    PointLight lamp = new PointLight();
    lamp.setPosition((new Vector3f(1f, 900f, 900f)).normalizeLocal());
    lamp.setColor(ColorRGBA.White);
    rootNode.attachChild(player);
    rootnode.addLight(lamp); //if you comment this out,all is darkness
    }
    /**
    *

    • @param control
    • @param channel
    • @param animName
      */
      public void onAnimCycleDone(AnimControl control,
      AnimChannel channel, String animName) {
      if (animName.equals(“Walk”)) {
      channel.setAnim(“Idle”,0.50f);
      channel.setLoopMode(LoopMode.DontLoop);
      channel.setSpeed(1f);
      }
      }

    /**
    *

    • @param control
    • @param channel
    • @param animName
      */
      public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
      //unused
      }

private void initKeys() {
inputManager.addMapping(“Walk”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, “Walk”);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“Walk”) && !keyPressed) {
if (!channel.getAnimationName().equals(“Walk”)) {
channel.setAnim(“Walk”, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};
}

/**
*

  • @author owner
    */

Thank you


“Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Test1.simpleInitApp(Test1.java:63)
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)”

What is Test1.java:63?

99 times out of 100, this is because you are trying to do stuff with a control that doesn’t exist where you think it does. It might be on a child for example.

Test1.java is my main class I renamed from the default Main.java As it’s a game work in progress for now and I’ll rename it back to Main.java once it’s fully done and completed.

player.getChild(“player”).getControl(AnimControl.class);

Also a little BQ How can I contribute to JME3 Engine,team,community? I can’t really help on the forms as I’ll probably ask more questions than I can answer as I am a novice/noob/beginner myself.

@jmenb said: Test1.java is my main class I renamed from the default Main.java As it's a game work in progress for now and I'll rename it back to Main.java once it's fully done and completed.

I meant the line number. The line number shows where your problem is.

@jmenb said: Also a little BQ How can I contribute to JME3 Engine,team,community? I can't really help on the forms as I'll probably ask more questions than I can answer as I am a novice/noob/beginner myself.

Probably: learn more, answer the questions you can. Not sure what else there would be to do if you don’t know the engine.

Ok, thanks
The line problem is " player.getChild(“player”).getControl(AnimControl.class); "
But in the scene composer I have renamed the name node to player which contains the material,animcontrol,skeleton control etc

@jmenb said: Ok, thanks The line problem is " player.getChild("player").getControl(AnimControl.class); " But in the scene composer I have renamed the name node to player which contains the material,animcontrol,skeleton control etc

Well, somehow apparently not. Are you sure it’s “player” and not “Player”? Maybe the name was changed but you didn’t save it?

You could also use System.out.println() to print all of the children of the player model and see what’s actually there.

Thanks for taking alot of time to help me.

I have made sure to rename all to Lowercase
Also I have changed the j3o to xml in the code as they were in the same folder to see if that will work but just made more errors.
And I have put the
System.out.println(); before the player.getChild(“player”).getControl(AnimControl.class); (is that were i am suppose to put it)

(I have now changed back to j3o) so still the same old

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Test1.simpleInitApp(Test1.java:64)
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)

System.out.println(); before the player.getChild(“player”).getControl(AnimControl.class); (is that were i am suppose to put it)
…if there is nothing called “player” in your player node then this will still throw an exception. The point was to print THE CHILDREN so you can see if you even have a player node.

@pspeed said: You could also use System.out.println() to print all of the children of the player model and see what's actually there.

System.out.println(“The children:” + player.getChildren());

Or:
[java]
for( Spatial s : player.getChildren() ) {
System.out.println(“Child:” + s + " with name:" + s.getName());
}
[/java]

Ok, I now think we are getting somewhere now its back to my previous error

player:[Material.001 (Geometry), Bone.077_attachnode (Node), player (Node)]
Nov 16, 2014 7:53:13 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalArgumentException: Cannot find animation named: ‘Idle’
at com.jme3.animation.AnimChannel.setAnim(AnimChannel.java:252)
at com.jme3.animation.AnimChannel.setAnim(AnimChannel.java:286)
at mygame.Test1.simpleInitApp(Test1.java:67)
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)

Line 67 is channel.setAnim(“Idle”);

Again, probably a good idea to do a little debugging with system.out.printlns:
http://hub.jmonkeyengine.org/javadoc/com/jme3/animation/AnimControl.html#getAnimationNames()

It’s a good idea to have the javadoc open all the time and constantly be asking yourself what assumptions you are relying on… then verify them.