我有 Gradle 项目和 2 个 IDE:NetBeans 和 IntelliJ。 NetBeans 与该项目完美配合,没有发现任何错误。 但是同一个项目中的IntelliJ抛出异常:
[Assets] error: com.badlogic.gdx.utils.GdxRuntimeException: File not found: ./images/enemy.atlas (Internal)
这是 Java 类:
public class Assets {
public static AssetManager assetManager;
public Assets() {
assetManager = new AssetManager();
try {
assetManager.load("./images/enemy.atlas", TextureAtlas.class);
assetManager.load("./images/buttons.atlas", TextureAtlas.class);
assetManager.load("./fonts/000.fnt", BitmapFont.class);
assetManager.load("./fonts/111.fnt", BitmapFont.class);
assetManager.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
assetManager.load("./world/level1/map.tmx", TiledMap.class);
assetManager.finishLoading();
} catch (GdxRuntimeException e) { if (Variables.isDebug) System.err.println("\n[Assets] error: " + e + "\n"); }
}
}
很简单吧?因此,我查看了 *.gradle 文件并注意到 gradle 知道在哪里搜索我的 Assets :
project.ext.assetsDir = new File("../android/assets");
我专门为 IDEA 重新制作了项目(使用 gdx-setup.jar),但出现了同样的问题。我很困惑,求指教!
附注AssetManager 是 LibGDX 1.1.0 库的一类。
最佳答案
您是否尝试过省略路径开头的 ./
?请参阅:https://github.com/libgdx/libgdx/wiki/Managing-your-assets#loading-assets
./
通常引用当前目录,但我不知道 libgdx 如何处理它。我无法以某种方式将其作为评论发布。
关于java - 使用 IntelliJ IDEA 找不到文件异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24774904/