Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

Something in line 85 of Game's move() method is null. 'move() is improperly named 'Move()'. Add print statements or other indicators to determine which item is null and then fix it. (We can't tell which line is line 85 or which item is null even if we knew which line was line 85 from the code you've posted, so there's not much more we can do.)

April 19th, 2014, 06:34 AM

RigaCrypto

Re: Java SnakeGame

So line 85 is:

Code :

Point head = snake.peekFirst();

The declaration of the variable:

Code :

private LinkedList<Point> snake;

The initialization of the snake variable in paint method + snake generator:

The paint() method is NOT a good place to initialize variables. paint() can be called for various reasons at different ttimes.
If the variable should be initialized one time, it better to do it in the constructor.

April 21st, 2014, 07:25 AM

RigaCrypto

Re: Java SnakeGame

Quote:

Originally Posted by Norm

The paint() method is NOT a good place to initialize variables. paint() can be called for various reasons at different ttimes.
If the variable should be initialized one time, it better to do it in the constructor.

Same thing hapens

April 21st, 2014, 08:15 AM

Norm

Re: Java SnakeGame

Please copy the full text of the error message and paste it here.
Also post the new code that causes the error.

April 21st, 2014, 08:57 AM

RigaCrypto

Re: Java SnakeGame

Quote:

Originally Posted by Norm

Please copy the full text of the error message and paste it here.
Also post the new code that causes the error.

It's the same error message as above.

April 21st, 2014, 09:09 AM

Norm

Re: Java SnakeGame

It can't be if you changed the program.
If you didn't change the program, nothing will change and it will be the same.

Exception in thread "main" java.lang.NullPointerException
at Game.move(Game.java:85)
at Game.run(Game.java:244)
at Game.main(Game.java:38)

April 21st, 2014, 09:59 AM

Norm

Re: Java SnakeGame

The code STILL has the call to the method: GenerateDefaultSnake() INSIDE of the paint() method.
Code that is used one time to initialize variables should NOT be in the paint() method.
Move the call to that method out of paint().