I'm getting a NullPointerException
when trying to add a new instance of a Block class to an ArrayList
called blocks.
Here is the code snippet containing the line of error:
public class Level1State extends GameState {
private Player player;
private ArrayList<Block> blocks;
public Level1State(GameStateManager gsm) {
super(gsm);
this.blocks = new ArrayList<Block>();
}
@Override
public void init() {
player = new Player(30, 30);
blocks.add(new Block(500, 400));
}
...
}
And the Block class is very simple:
public class Block extends Rectangle {
private static final long serialVersionUID = 1L;
public static final int blockSize = 64;
public Block(int x, int y) {
setBounds(x,y,blockSize,blockSize);
}
public void tick() {
}
public void draw(Graphics g) {
g.setColor(Color.DARK_GRAY);
g.fillRect(x - (int) GameState.xOffset, y - (int) GameState.yOffset,
width,
height);
}
}
Any help is appreciated.