NullPointer on adding animation listener


I’ve been following the testOgreAnim demo, but I can’t figure out what I’m doing wrong for setting up my animation listener. I’m getting a nullpointerexception when I’m adding a single listener.

the method we are putting this animation in also controls the physics, so you can skip the forst part of this if you like. Below is the constructor which is where I also initialize the controller and add the listener

[java] public class WorldPhysics extends AbstractAppState implements ActionListener, PhysicsCollisionListener, AnimEventListener {

private BulletAppState bulletAppState;

private PhysicsSpace physicsSpace;

private CapsuleCollisionShape capsuleShape;

private CharacterControl character_phys;

private Spatial player;

private AppStateManager stateManager;

private Node moveTo;

private DefaultCamSystem camSys;

private Geometry mark;

private Node rootNode;

private InputManager inputManager;

private Vector3f walkDirection;

private float airTime = 0;

private AnimChannel avatarChannel;

private AnimControl avatarControl;

private ArrayList<Spatial> players;

private boolean left = false, right = false, up = false, down = false;

public WorldPhysics(AppStateManager stateManager, Spatial WorldRoot, Spatial player, DefaultCamSystem camSys, InputManager inputManager) {

this.inputManager = inputManager;


bulletAppState = new BulletAppState();

this.stateManager = stateManager;

this.camSys = camSys;

walkDirection = new Vector3f();


//Sets up the physics space for this bulletappstate

physicsSpace = bulletAppState.getPhysicsSpace();

physicsSpace.setGravity(new Vector3f(0f, -2f, 0f));


//This is a temporary Player physics to get a feel of working with physics

this.player = player;

capsuleShape = new CapsuleCollisionShape(1.5f, 1f, 1);

character_phys = new CharacterControl(capsuleShape, 5f);




players = new ArrayList<Spatial>();


avatarControl = player.getControl(AnimControl.class);


avatarChannel = avatarControl.createChannel();

for (String names : avatarControl.getAnimationNames()) {





The specific Error I’m getting is:

Oct 6, 2011 3:59:36 PM handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,6,main]
at com.benkyou.util.WorldPhysics.(
at Main.simpleInitApp(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(

If anyone has an idea why this is coming up null. thanks

edit: The avatar is loaded in a small separate class - its below for

[java]public class Player extends Node{
private String[] avatarLoader = {
private Spatial avatar;
private AssetManager assetManager;
private int id;
public Player(AssetManager assetManager, int avatarNumber){
this.assetManager = assetManager;
avatar = assetManager.loadModel(avatarLoader[avatarNumber]);

The animControl is probably null. You sure the “player” spatial is the one that actually has the AnimControl attached?

ya it seems it is. what else could be happening?

See, a nullpointer is easy to trace. Some variable in that line was null and still a method was called on it. Just check which of the objects is null in line 106 and then find out why it is null.