0

私は自分のプレーヤークラスに次のコードを持っています:

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);
}

なぜこれを行うのですか?私は今、何時間もこれを理解しようとしています。どんな助けでも大歓迎です!

4

2 に答える 2

1

通常、これは画像に指定したパスが間違っていることを意味します

 front = new Image("res/steveFront.png")

これがsrcフォルダーにある場合は、getResourceを使用する必要があります

于 2012-11-09T00:49:04.747 に答える
0

変数「front」を静的ではないものにしてみてください

于 2012-11-09T00:56:03.707 に答える