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

Hi all, Im new here.

Im followed the “Hello animation tutorial” with a model that I created, but its giving me an error when I add a listener to the control
here is the line code:
[java]control.addListener(this);[/java]

The code is practically the same of “Hello Animation”. Could anyone tell me what it must be?

Here is the error:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.teste.GameTeste.simpleInitApp(GameTeste.java:46)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
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:722)

here is my full code
[java]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.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import sun.swing.PrintColorUIResource;

public class GameTeste extends SimpleApplication
implements AnimEventListener{
private AnimChannel channel;
private AnimControl control;
Node player;
public static void main(String[] args) {
GameTeste app = new GameTeste();
app.start();
}

@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.LightGray);
initKeys();
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
rootNode.addLight(dl);
player = (Node) assetManager.loadModel(“Models/Cube.mesh.xml”);
player.setLocalScale(0.5f);
rootNode.attachChild(player);
control = player.getControl(AnimControl.class);
control.addListener(this);
channel = control.createChannel();
channel.setAnim(“stand”);
}

public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {
if (animName.equals(“stand”)) {
channel.setAnim(“rotateX”, 0.50f);
channel.setLoopMode(LoopMode.DontLoop);
channel.setSpeed(1f);
}
}

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

/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
inputManager.addMapping(“rotateX”, new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(actionListener, “rotateX”);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“rotateX”) && !keyPressed) {
if (!channel.getAnimationName().equals(“rotateX”)) {
channel.setAnim(“rotateX”, 0.50f);
channel.setLoopMode(LoopMode.Loop);
}
}
}
};

}[/java]

You have to show your code and the full exception stack trace before anyone can help you =)

Хочу построить дома по канадской технологии, но интересуют отзывы по этим технологиям. Дайте советов народ!

What is this line:
com.teste.GameTeste.simpleInitApp(GameTeste.java:46)

It did not line up with anything relevant in the code you posted. That’s where the NPE is… in your code.

@pspeed said: What is this line: com.teste.GameTeste.simpleInitApp(GameTeste.java:46)

It did not line up with anything relevant in the code you posted. That’s where the NPE is… in your code.

the NPE is here

[java]control = player.getControl(AnimControl.class);

//the line below i get the error
control.addListener(this);

channel = control.createChannel();[/java]

The player object does not have an AnimControl.

@pspeed said: The player object does not have an AnimControl.

You’ve got to tell me your secret to stay calm that way. I thought of replying but… yeah. Wouldn’t have been nice. XD

@pspeed said: The player object does not have an AnimControl.

Ok, Thanks!! But i really did the animation with all recomendation, what do you think it might be?

I really sorry guys to bother you with these stupid things but im really new on this.

@paulinhu said: I really sorry guys to bother you with these stupid things but im really new on this.

This has nothing to do with being new. It has to do with LOGIC. Something many new programmers don’t seem to have aplenty…

Look, this is how it goes:

You have a class-global PRIVATE AnimControl named control.

  • This means ONLY the class in which it’s define can access and modify it.

You tell your program to assign a value to control here:
[java]control = player.getControl(AnimControl.class);[/java]

The following line you tell your program to use control you just got and do something with it.

Now, that line has 3 components.

1 - control
2 - .addListener(…)
3 - this

  1. control is the AnimControl we just got.
  2. is a method in the control class.
  3. this is the class in which it is declared.

If the error was with #2, the SDK would give you a red squiggle and the program wouldn’t run. At worse it would run but spew a different error than NPE.
It can’t be #3 because that’s not possible. The class exists since you’re written code in it… Yeah…
It can ONLY be 1.

That’s LOGICAL reasoning.

@paulinhu said: Ok, Thanks!! But i really did the animation with all recomendation, what do you think it might be?

I really sorry guys to bother you with these stupid things but im really new on this.

If AnimControl is null then something went wrong here:
player = (Node) assetManager.loadModel(“Models/Cube.mesh.xml”);

As far as JME is concerned, Cube.mesh.xml does not have any animation. I don’t think you should be loading the mesh.xml’s directly anyway and should instead be importing them and turning them into a .j3o. I would have thought the tutorials covered that but I’ve never looked at them.

@pspeed said: If AnimControl is null then something went wrong here: player = (Node) assetManager.loadModel(“Models/Cube.mesh.xml”);

As far as JME is concerned, Cube.mesh.xml does not have any animation. I don’t think you should be loading the mesh.xml’s directly anyway and should instead be importing them and turning them into a .j3o. I would have thought the tutorials covered that but I’ve never looked at them.

I tried to do a lot of things but i really dont know what is happening, even when i use .j3o i have the same error, i think it must be and error when im exporting to ogre from my blend file (Which stil arent making sense, i did my animation with all recomendation). I dont know what i gonna do next… but you was very helpful PSPEED thank you for your time!

It may also depend on the way you built your J3O in JME.
Open it with the scene explorer and take a look at where the AnimControl is attached.

Sometimes you have a scene node that contains an object node that contains the animation.
-> getting the animation from the scene node will fail
-> getting it from the child would work (in this case)

Hi guys.
I collide with this trouble too.
I create model in blender and convert it into j3o format.
In scene composer i can observe the AnimControl branch with 2 actions (stand and Walk, like in tutorials).
Then i use the code from tutorial “Hello Animation”.
And after all this i receive the error like in post above.
As i understand, my model is very cool, and because of this it does not work :slight_smile: .
Please, guys, look on this model and say me, what is wrong???
Blender model

@Separator2 said: Hi guys. I collide with this trouble too. I create model in blender and convert it into j3o format. In scene composer i can observe the AnimControl branch with 2 actions (stand and Walk, like in tutorials). Then i use the code from tutorial "Hello Animation". And after all this i receive the error like in post above. As i understand, my model is very cool, and because of this it does not work :) . Please, guys, look on this model and say me, what is wrong??? Blender model

We would need to actually see the exception and stack trace. Otherwise we could just randomly guess at things until one sticks.

@pspeed said: What is this line: com.teste.GameTeste.simpleInitApp(GameTeste.java:46)

It did not line up with anything relevant in the code you posted. That’s where the NPE is… in your code.

I know someone else already answered your question… but to me… it just looks like a few test-ee’s.

/badpun off

Now back to the schedule thread in progress.

We would need to actually see the exception and stack trace. Otherwise we could just randomly guess at things until one sticks.
Exception: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] NullPointerException All other data: Stack trace, source code etc

I wish you could have just pasted the stack trace into a code block. I think many (myself included) don’t have time to download and extract a .rar just to see a stack trace.

Some like this? :slight_smile:
[java]
run:
фев 15, 2013 2:06:57 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.0.0 Beta
фев 15, 2013 2:06:57 PM com.jme3.system.Natives extractNativeLibs
INFO: Extraction Directory: D:\games\jMonkey\BasicGame
фев 15, 2013 2:06:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay run
INFO: Using LWJGL 2.8.4
фев 15, 2013 2:06:57 PM com.jme3.system.lwjgl.LwjglDisplay createContext
INFO: Selected display mode: 640 x 480 x 0 @0Hz
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: atiu9p64
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: 8.14.1.6099
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: ATI Technologies Inc.
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 3.2.9704 Compatibility Profile Context
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: ATI Mobility Radeon HD 5650
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 1.50
фев 15, 2013 2:06:58 PM com.jme3.system.lwjgl.LwjglTimer
INFO: Timer resolution: 1 000 ticks per second
фев 15, 2013 2:06:58 PM com.jme3.renderer.lwjgl.LwjglRenderer initialize
INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, TextureMultisample, OpenGL20, OpenGL21, OpenGL30, OpenGL31, OpenGL32, ARBprogram, GLSL100, GLSL110, GLSL120, GLSL130, GLSL140, GLSL150, VertexTextureFetch, TextureArray, TextureBuffer, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, TextureCompressionLATC, NonPowerOfTwoTextures, MeshInstancing, VertexBufferArray, Multisample, PackedDepthStencilBuffer]
фев 15, 2013 2:06:58 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
фев 15, 2013 2:06:58 PM com.jme3.asset.DesktopAssetManager
INFO: DesktopAssetManager created.
фев 15, 2013 2:06:58 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
фев 15, 2013 2:06:58 PM com.jme3.renderer.Camera
INFO: Camera created (W: 640, H: 480)
фев 15, 2013 2:06:58 PM com.jme3.input.lwjgl.LwjglMouseInput initialize
INFO: Mouse created.
фев 15, 2013 2:06:58 PM com.jme3.input.lwjgl.LwjglKeyInput initialize
INFO: Keyboard created.
фев 15, 2013 2:06:58 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
фев 15, 2013 2:06:58 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio effect extension version: 1.0
фев 15, 2013 2:06:58 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio max auxilary sends: 4
фев 15, 2013 2:06:58 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Unshaded
фев 15, 2013 2:06:58 PM com.jme3.scene.Node attachChild
INFO: Child (BitmapFont) attached to this node (null)
фев 15, 2013 2:06:58 PM com.jme3.material.MaterialDef
INFO: Loaded material definition: Phong Lighting
фев 15, 2013 2:06:58 PM com.jme3.scene.Node attachChild
INFO: Child (Models/Radar/rad.blend) attached to this node (Root Node)
фев 15, 2013 2:06:58 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main.simpleInitApp(Main.java:41)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
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:722)

фев 15, 2013 2:06:58 PM com.jme3.renderer.lwjgl.LwjglRenderer cleanup
INFO: Deleting objects and invalidating state
фев 15, 2013 2:06:59 PM com.jme3.input.lwjgl.LwjglMouseInput destroy
INFO: Mouse destroyed.
фев 15, 2013 2:06:59 PM com.jme3.input.lwjgl.LwjglKeyInput destroy
INFO: Keyboard destroyed.
фев 15, 2013 2:06:59 PM com.jme3.system.lwjgl.LwjglAbstractDisplay deinitInThread
INFO: Display destroyed.
СБОРКА УСПЕШНО ЗАВЕРШЕНА (общее время: 10 секунды)

[/java]

There’s a NULL at line 41 that’s not expected to be there… That’s all we can say because, you know… we can’t guess code lines of other people. At least I can’t.

In the post above, I have posted the source code and 3D models.
Please, help me understand, what wrong in blend model, and why AminControl not available?