[SOLVED] Hello Update Loop issue

hi,
I saw how you can make a rotating cube and thought wow thats cool for my collectable and wanted my collectible to rotate. First I tried it with the box in the tutorial and everything was fine. Then I tried it with my spatial and it gave a NullPointerException trying to run it.

This is my code about the collectable and rotating it:
private Spatial collectable;

//in the simpleInit:
Spatial collectable = assetManager.loadModel(“Models/Cranio.j3o”);
collectable.setLocalTranslation(100, 3, -109);
rootNode.attachChild(collectable);
collectable.scale((float) 0.5);

//in the SimpleUpdate:
collectible.rotate(0, 2*tpf, 0);

A) Search for the forum post “how to type code blocks”, or simply click on the </> logo after you selected the text.
B) Is that really the code? The simpleUpdate method shows collectible whereas simpleInit shows collectable
C) append f for your numbers then they are seen as float

private Spatial collectable;

//in the simpleInit:
Spatial collectable = assetManager.loadModel("Models/Cranio.j3o");

Yeah, your problem is that the second “Spatial collectable” is hiding the private field collectable. Delete the second “Spatial”. Based on that code your NPE is happening in SimpleUpdate when it accesses the uninitialized private collectable Spatial. Normally NetBeans (if you’re using the SDK) warns you about that.

Thanks for the fast reply, this fixed it. I’ve just started yesterday so this is all new for me :stuck_out_tongue_closed_eyes: