I want to access the world Variable "foodEaten" but the game can not be started due to two NullPointerExeptions. One in the Class "SnakeHead" (line 14) and one in the World Class "Grid" (line 13). Please Help!
Class "SnakeHead":
Class "Grid":
public class SnakeHead extends Actor
{
private final int EAST = 0;
private final int SOUTH = 90;
private final int WEST = 180;
private final int NORTH = 270;
private final int SPEED = 10;
private int counter = 0;
private int foodEaten ((Grid)getWorld()).foodEaten;
private GreenfootImage SnakeHead = new GreenfootImage("Head.png");
public SnakeHead()
{
setImage("Black Head.png");
setRotation(Greenfoot.getRandomNumber(4)*9);
}public class Grid extends World
{
public int foodEaten = 0;
public Grid()
{
super(30, 20, 20); //super (600, 400, 1)
setBackground("Rasenfläche.png");
int x = Greenfoot.getRandomNumber(getWidth()-2)+1;
int y = Greenfoot.getRandomNumber(getHeight()-2)+1;
addObject(new SnakeHead(), x, y);
addFood();
}
