Problem with click a model

in my game, when a model is clicked, an event must occur

but this only works when you click a BOX, SPHERE … when you click a model.j3o, an error occurs.

my function:

private void initClick()



new KeyTrigger(KeyInput.KEY_F1), // trigger 1: spacebar

new MouseButtonTrigger(1)); // trigger 2: left-button click

inputManager.addListener(actionListener, "Shoot");


private ActionListener actionListener = new ActionListener()



public void onAction(String name, boolean keyPressed, float tpf)


if (name.equals("Shoot") && !keyPressed)


// 1. Reset results list.

CollisionResults results = new CollisionResults();

// 2. Aim the ray from cam loc to cam direction.

Ray ray = new Ray(cam.getLocation(), cam.getDirection());

// 3. Collect intersections between Ray and Shootables in results list.

//andares[indexAndar].pegaApIndex().pegaComodoIndex().getNode().collideWith(ray, results);

rootNode.collideWith(ray, results);

// 4. Print the results.


Collisions? " + results.size() + "
for (int i = 0; i < results.size(); i++) {
// For each hit, we know distance, impact point, name of geometry.
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getContactPoint();
String hit = results.getCollision(i).getGeometry().getName();
if (hit != null)
System.out.println("* Collision #" + i);
System.out.println(" You shot " + hit + " at " + pt + ", " + dist + " wu away.");
click (hit);


error when click a model.j3o:

Collisions? 2
Exception in thread "LWJGL Renderer Thread" java.lang.NullPointerException
at V3D.Controller.Cena$1.onAction(
at com.jme3.input.InputManager.invokeActions(
at com.jme3.input.InputManager.onMouseButtonEvent(
at com.jme3.input.lwjgl.LwjglMouseInput.update(
at com.jme3.input.InputManager.update(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
at com.jme3.system.lwjgl.LwjglCanvas.runLoop(

line 195: String hit = results.getCollision(i).getGeometry().getName();

Can someone help me?



The NPE is is your own code, this is not an engine issue.


I’m with Normen. I saw this post when you originally came up and thought I’d be able to figure it out, but there’s really just not enough information to troubleshoot it accurately. Post more code I guess :shrug:

If I had to take a shot in the dark, when I originally looked at this I thought maybe the geometry you’ve got there just has no name, so it NPE’s. But it’s just a string, so I’d be wondering why it wouldn’t work as is and you’d just get a null string. Also, given where it NPE’s, is there a possibility that the collision you’re checking does not have a geometry? If you do a hit collision test on just a bounding box, it’s going to go boom when it tries to get the geometry.

That’s all I got. :<