#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0

    Need help for java.lang.NullPointerException


    NetBeans Output:
    Code:
    Exception in thread "main" java.lang.NullPointerException
    	at com.base.game.Game.getInput(Game.java:24)
    	at com.base.engine.main.getInput(main.java:31)
    	at com.base.engine.main.gameLoop(main.java:54)
    	at com.base.engine.main.main(main.java:20)
    How to fix: Check every single variable in the program and see if they are null. If null, initialize them.
    Last edited by nerr__; September 15th, 2013 at 12:17 PM. Reason: Fixed source thing
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Exception in thread "main" java.lang.NullPointerException
    at com.base.game.Game.getInput(Game.java:24)
    Look at the code on line 24 and find the variable with the null value. Then backtrack in the code to see why that variable does not have a valid value.
    If you can't tell which variable has the null value, use the println method to print out the values of all the variables used on line 24 to show which is null.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    2
    Rep Power
    0
    Nevermind! I figured it out!
    Code:
     if(player == null)
                player = new Player(Display.getWidth() / 2 - Player.SIZE / 2, Display.getHeight() / 2 - Player.SIZE / 2);
                
            if(objects == null)
                objects = new ArrayList<GameObject>();
                objects.add(this.player);
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Code:
    24 ->  player.getInput();
    player is the variable on line 24. Make sure that is has a valid, non-null value before using it.

IMN logo majestic logo threadwatch logo seochat tools logo