Want to navigate a chracter with mouse click but get a null pointer exception

Hello everyone,

i want to create a hack and slash game like Diabolo or Torchlight but very simple because it’s my first own project with the jme after i read the beginners guide book.
My problem is that i become a null pointer exception when i click on the ground to move my character.

The link opens my project hostet at gitlab: My Game.
After debugging the code i found that the exception throwed here Exception.

I didn’t found any solution for my problem at google or in this forum so i would be happy if anybody has some ideas what i can do.

Thanks for help,
Rinma

The Exception-link does not work.
Could you post the code that is executed when you click on the ground to move your character?
That would be better than making everyone crawl through your project directorys and files.

Here are the correct link for the exception:
PlayerState.java, Line 66

Just guessing now, but if
[java]System.out.println("X: " + clickPos.getX()
+ " Y: " + clickPos.getY());[/java]
works, then the thing in line 66 that could be the cause for the exception is
[java]cam.getWorldCoordinates([/java]
Maybe your camera is null?

1 Like

I think you are right. I run this code before line 66: [java]System.out.println(cam.getLocation());[/java] an the exception throws there too.

Any ideas how i can implement “click to run at this position” in a other way?

I know i can make a ray cast and get the position where the collision happens. But how can i do this without the cam object?

I have never used appStates but why don’t you just use a setter for the camera?
Somewhere you extend a SimpleApplication, right?
Just set the Camera of your PlayerState there. Or you can just give the camera to the state as a parameter in the constructor.
If that’s the problem, this is very basic stuff.

1 Like

Ah Thanks i found the problem.

I have created a camera node that follows the character. Now i have gave “cam” the camera from this node an now everthing works fine.

[java]
this.followCam = new CameraNode(“Follow Cam”, this.app.getCamera());
this.followCam.setControlDir(CameraControl.ControlDirection.SpatialToCamera);

this.cam = this.followCam.getCamera();

player.attachChild(this.followCam);
[/java]

1 Like