September 15th, 2013, 11:46 AM
Need help for java.lang.NullPointerException
How to fix: Check every single variable in the program and see if they are null. If null, initialize them.
Exception in thread "main" java.lang.NullPointerException
Last edited by nerr__; September 15th, 2013 at 12:17 PM.
Reason: Fixed source thing
September 15th, 2013, 12:01 PM
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.
September 15th, 2013, 12:07 PM
Nevermind! I figured it out!
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>();
September 15th, 2013, 12:15 PM
player is the variable on line 24. Make sure that is has a valid, non-null value before using it.
24 -> player.getInput();