0
所以我試圖加載使用Slick2D的圖像,但由於某種原因,我得到以下錯誤,當我試着將圖像繪製到屏幕:Slick2D加載圖像不會工作
Sat Sep 28 16:37:59 NZST 2013 ERROR:null
java.lang.NullPointerException
at org.newdawn.slick.Graphics.drawImage(Graphics.java:1350)
at org.newdawn.slick.Graphics.drawImage(Graphics.java:1399)
at Game.render(Game.java:58)
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 Game.main(Game.java:42)
Sat Sep 28 16:37:59 NZST 2013 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:706)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at Game.main(Game.java:42)
我用這載入我的形象:
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class Textures {
static Image grass;
Game game;
public Textures() {
try {
grass = new Image("grass.jpg");
} catch (SlickException e) {
e.printStackTrace();
}
}
}
我用這畫我的形象:
for(int x = 0; x < app.getWidth(); x+=32) {
for(int y = 0; y < app.getHeight(); y+=32) {
g.drawImage(textures.grass, x, y);
}
}
你曾經構建過一個Texture對象嗎?否則,構造函數將永遠不會被調用,並且grass將爲空。 – Clark
哪行是'Graphics.java'的第1350行? – Barett