Render error in simple App

Hello
Firstly im new to the forum so Hello everyone! :smiley:
I am learning basics with Jmonkeyengine book and I am at the setting button part.
here’s my code:
package mygame;

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.input.;
import com.jme3.input.controls.
;
import com.jme3.scene.Node;

/**

  • test

  • @author normenhansen
    */
    public class Main extends SimpleApplication {

    private final static Trigger TRIGGER_COLOR =
    new KeyTrigger(KeyInput.KEY_SPACE);
    private final static Trigger TRIGGER_ROTATE =
    new MouseButtonTrigger(MouseInput.BUTTON_LEFT);
    private final static String MAPPING_COLOR = “Toggle Color”;
    private final static String MAPPING_ROTATE = “Rotate”;
    private final static Trigger TRIGGER_COLOR2 =
    new KeyTrigger(KeyInput.KEY_C);
    private Geometry geom;

    public static void main(String[] args) {
    Main app = new Main();
    app.start();
    }

    @Override
    public void simpleInitApp() {

     Box b = new Box(1, 1, 1);
    
     Geometry geom = new Geometry("Box", b);
    
     Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
     mat.setColor("Color", ColorRGBA.Blue);
     geom.setMaterial(mat);
     Node nic = new Node();
     nic.attachChild(geom);
     rootNode.attachChild(nic);
     
     
     
     inputManager.addMapping(MAPPING_COLOR, TRIGGER_COLOR);
     inputManager.addMapping(MAPPING_ROTATE, TRIGGER_ROTATE);
     inputManager.addMapping(MAPPING_COLOR, TRIGGER_COLOR, TRIGGER_COLOR2);
     inputManager.addListener(actionListener,
             new String[]{MAPPING_COLOR});
     inputManager.addListener(analogListener,
             new String[]{MAPPING_ROTATE});
    

    }
    private ActionListener actionListener = new ActionListener() {
    public void onAction(String name, boolean isPressed, float tpf) {
    geom.move(0, 0, 1);
    }
    };
    private AnalogListener analogListener = new AnalogListener() {
    public void onAnalog(String name, float intensity, float tpf) {
    System.out.println("You triggered: " + name);

     }
    

    };

    @Override
    public void simpleUpdate(float tpf) {
    //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
    //TODO: add render code
    }
    }

and here’s whole error:

run:
maj 30, 2014 9:01:28 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.0.5
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Lwjgl 2.9.0 context running on thread LWJGL Renderer Thread
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: igdumdim64
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: 9.18.10.3107
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: Intel
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 4.0.0 - Build 9.18.10.3107
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: Intel® HD Graphics 4600
maj 30, 2014 9:01:28 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 4.00 - Build 9.18.10.3107
maj 30, 2014 9:01:28 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Device: OpenAL Soft
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Vendor: OpenAL Community
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Renderer: OpenAL Soft
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Version: 1.1 ALSOFT 1.15.1
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio effect extension version: 1.0
maj 30, 2014 9:01:28 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio max auxilary sends: 4
maj 30, 2014 9:01:28 AM com.jme3.input.InputManager addMapping
WARNING: Attempted to add mapping “Toggle Color” twice to trigger.
maj 30, 2014 9:01:29 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at mygame.Main$1.onAction(Main.java:63)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onKeyEventQueued(InputManager.java:455)
at com.jme3.input.InputManager.processQueue(InputManager.java:831)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)

BUILD SUCCESSFUL (total time: 6 seconds)

Please show me where I have an error.
I know that " geom.move(0, 0, 1); " cause error, but I tried to move node, rotate geom even when I try to move it by " geom.move(0, 0, 0); " I still have this error message.
Thanks for Your help :slight_smile:

geom.move(0, 0, 1);

geom is null because you’ve never set it to anything.

The SDK is giving you a warning on this line:
Geometry geom = new Geometry(“Box”, b);

DO NOT IGNORE THE WARNING.

And finally, for the future:

1 Like

I dont know how to understand your answer.
What You mean by " never set it to anything."
I have pinned it to a node, and the whole program is running, but when i try to move it by pressing space bar it crash.
I tried to move a node, and a geometry.
And thank you for quick answer! :smiley:

@pspeed said: The SDK is giving you a warning on this line: Geometry geom = new Geometry(“Box”, b);

DO NOT IGNORE THE WARNING.

Without actually telling you the exact answer, I don’t know what else to say other than DON’T IGNORE THE WARNING.

Look at that line in the SDK. Look at it again. Look at the yellow underline and the little yellow light bulb. Hover over it. Read it. Understand it.

Until you know Java well enough to ignore them, you should pay attention to all of those warnings.

I could tell you exactly what’s wrong but then you will make the same mistake in the future and still not know how to find it yourself. :wink:

Hinting a different a different way.

You have a nice refrigerator in your house. You made a sandwich at your friends house and put it in his refrigerator.

Later you wake up in the middle of the night at your house and want a snack. You look in your fridge and there is no sandwich… so you throw a NullPointerException when you try to eat it.

1 Like
@pspeed said: You have a nice refrigerator in your house. You made a sandwich at your friends house and put it in his refrigerator.

Later you wake up in the middle of the night at your house and want a snack. You look in your fridge and there is no sandwich… so you throw a NullPointerException when you try to eat it.

good one

Ok. Now i see it. This is method body and the variable was local. :smiley:
Thank you for your help :smiley: