我正在使用Java进行游戏,但在尝试绘制背景时偶然发现错误。我得到一个NullPointerException,但是我实际上无法找到null对象的位置/它来自哪里。
错误是:
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)
并指出这些:
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(我不认为这是相关的,但无论如何我都会把它包括在内
//game loop
while(running) {
tick();
/* this line! */ draw();
关于null对象在哪里的任何想法?
谢谢:)