なぜ機能しないのか理解できませんか?
私は自分のメソッドクラスを持っています:
package particles;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
public class Methods {
Graphics g;
public void showhud(){
g.setColor(Color.white);
g.drawString("Screen: Game", 675, 10);
g.drawString("Version: 1.0", 675, 25);
}
}
しかし、他のクラスに showhud() を実装しようとすると、うまくいきません!
これは私がそれを使用する方法です:
package particles;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import particles.Methods;
public class Game extends BasicGameState {
Methods m;
public void init(GameContainer container, StateBasedGame game) throws SlickException {
}
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
m.showhud();
}
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
}
public int getID() {
return 0;
}
}
私が得るエラーは次のとおりです。
Tue Jan 01 17:19:36 NZDT 2013 ERROR:null
java.lang.NullPointerException
at particles.Game.render(Game.java:18)
at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:207)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:703)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at particles.Main.main(Main.java:23)