Stuck with the FlagRush first tutorial (NullPointerException in the update meth)

Hello,



I hope I m not too annoying with all my questions… :mrgreen:



I m going through the first tutorial (about Flag Rush) and I m stuck again…



The problem seems to come from the update method. I ve already written the rest.


 @Override
    protected void update(float interpolation) {

      
       timer.update();
       interpolation = timer.getTimePerFrame();
      
       //if escape was pressed, we exit
       if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
          finished = true;
       }
      

    }



When I execute the "game", I get the settings dialog, and then, a black screen (the game) and no sphere that directly shuts down. The console gives me a NullPointerException in the update method.

I think the problem comes from the timer, because if I put the first two lines in comments, I get a nice black screen with my textured sphere in the center.

I really dont know how to fix that...

Anyways here s the complete code:


package flag_rush;

import com.jme.app.BaseGame;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;

/**
 *
 * @author BAROZFR4
 */
public class Game extends BaseGame {

    protected int width, height, depth, freq;
    protected boolean fullscreen;
    protected Camera cam ;
    protected Timer timer;

    private Node scene;
    private TextureState textState;


    @Override
    protected void initSystem() {

        
        //Propri

is the timer being created…

if you are new i would strongly recommend you use SimpleGame for a while to get used to other more basic aspects of jme rather than having to dig around with bootstrap code…

Posting the exception would sure help us out…

hey,  :wink:



yes I m new ^^ but I ve already been through everything I could find regarding jME2 and SimpleGame…



About the timer s creation, I have a line in the initSystem() method that says:


timer.getTimer();



And I guess I couldn t do better since Timer is an abstract class and can therfore not be instantiated...

The exception says:


GRAVE: Exception in game loop
java.lang.NullPointerException
        at flag_rush.Game.update(Game.java:114)
        at com.jme.app.BaseGame.start(BaseGame.java:84)
        at flag_rush.Game.main(Game.java:154)
28 ao

Oooop I found where the problem comes from ^^



For getting the timer, I wrote:


timer.getTimer();



instead of

timer = timer.getTimer();



stupid mistake... Thanks ncomp for your hint ^^