我的播放器类有以下代码:
public class Player {
private static Image front;
int posX = 400;
int posY = 300;
public void player() throws SlickException{
init(null, null);
render(null, null, null);
update(null, null, (Integer) null);
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
front = new Image("res/steveFront.png");
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
front.draw(posX, posY);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
}
}
这是我的主要游戏课程:
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
map.render(gc, sbg, g);
player.render(gc, sbg, g);
}
当我运行代码时,它会调用 javanullpointer 异常
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
front.draw(posX, posY);
}
为什么这样做?几个小时以来,我一直试图弄清楚这一点。任何帮助,将不胜感激!