我正在使用 Codename One 构建一款小游戏。我的游戏可以在模拟器中运行,但是,每当我运行游戏的 Android 版本时,我都会遇到
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.BufferedReader.close()' on a null object reference
我使用 if 语句来简单地关闭输入流(如果它不为空),但随后没有加载任何内容,在我看来,我没有正确配置我的资源。
这就是我加载图像资源的方式:
public static final String DUCKY_ATLAS = "/duckySprite.png";
public static final String LEVEL_ATLAS = "/mapSprite.png";
public static final String START_LEVEL = "/levelOne.png";
public static final String OBSTACLE_SEQUENCES = "/levelSequences.png";
//method to pull Image from file
public static Image getSpriteAtlas(String file) {
Image img = null;
try {
InputStream is = CN.getResourceAsStream(file);
img = Image.createImage(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return img;
}
我的资源文件夹的位置如下所示:/common/src/main/resources
其中也没有嵌套。
任何帮助将不胜感激。
由于根本没有声明,可能会发生空指针异常。