【发布时间】:2013-10-19 22:11:27
【问题描述】:
我正在尝试为我的游戏制作加载页面。 我的代码是这样的:
manager = new AssetManager();
game = new Game(level);
game.startLoadingTextures(manager);
public void startLoadingTextures(AssetManager manager){
manager.load("data/background.png" ,Texture.class);
}
在更新函数中我有这个:
if (manager.update()){
game.setTexture(manager);
}
什么是setTexture函数?我从经理那里得到所有的纹理。
public void setTexture(AssetManager manager) {
System.out.println("entered here");
background = manager.get("data/background.png" ,Texture.class);
}
我得到这个错误:
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.smeurares.game.Loading.update(Loading.java:31)
第 31 行是game.setTexture(manager),在输入函数之前我得到了这个错误,因为System.out.println("entered here"); 没有出现在控制台中。
我做错了什么?
【问题讨论】:
-
game必须是null直到您到达第 31 行。使用调试器并逐步检查您的代码以找出为什么它是null