September 15th, 2013, 10: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 11:17 AM.
Reason: Fixed source thing
September 15th, 2013, 11:01 AM
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, 11:07 AM
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, 11:15 AM
player is the variable on line 24. Make sure that is has a valid, non-null value before using it.
24 -> player.getInput();