我无法理解为什么它不起作用?
我有我的方法类:
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)