0

I am working on a game in Java but stumbled on an error when trying to draw a background. I am getting a NullPointerException, however I can't actually find where the null object is/where it's coming from.

The error is:

Exception in thread "Thread-2" java.lang.NullPointerException
at GameState.Level1State.draw(Level1State.java:39)
at GameState.GameStateManager.draw(GameStateManager.java:34)
at main.GamePanel.draw(GamePanel.java:91)
at main.GamePanel.run(GamePanel.java:70)
at java.lang.Thread.run(Thread.java:745)

and points to these:

Level1State

public void draw(Graphics2D g) {

    /* this line! */ bg.draw(g);

    //draw tilemap
    tileMap.draw(g);

}

GameStateManager

public void draw(Graphics2D g) {
    /* this line! */ gameStates.get(currentState).draw(g);
}

GamePanel

private void draw() {
    /* this line! */ gsm.draw(g);
}

GamePanel (I don't think this is relevant but I will include it anyways

//game loop
    while(running) {

        tick();
        /* this line! */ draw();

Any ideas on where the null object is?

Thanks :)

Jashaszun
  • 9,207
  • 3
  • 29
  • 57
Muggles
  • 1
  • 1
  • 1
    Exactly where it says it is - that line. How are you setting up `bg`? – kolossus Jul 28 '15 at 15:18
  • Sorry, should have worded it differently. I meant I cant find what is causing it, not where it is. I am declaring bg as a private Background, and then in my init method I am doing: bg = new Background(bgPath, 0.1); – Muggles Jul 28 '15 at 15:40

0 Answers0