我对该字段有疑问:
public TextureRegion guiButton = new TextureRegion(new Texture(Gdx.files.local("gui_button.png")));
我将该图像打包到 assets
文件夹中。我构建了一个游戏,启动并崩溃: com.badlogic.gdx.utils.GdxRuntimeException:
无法加载文件:gui_button.png 等...我解压了 apk
并且文件位于正确的位置( Assets 目录)且名称正确!我对这种情况感到非常困惑。
最佳答案
就像 Tenfour04 所说:您几乎应该始终使用 Gdx.files.internal();
访问您的资源(纹理、声音、字体等)。本地主要用于当您想要写入文件并稍后读取已写入的文件时。
此外,如果您仍然遇到问题并且使用 Eclipse 作为 IDE,您可以尝试以下操作:
Right-click your project > 'Gradle' > 'Refresh Gradle Project.'
您也可以尝试这个:
Press the 'Project' header at the top of Eclipse > Press 'Clean...' and then press'OK' in the pop up menu.
关于java - 无法加载文件。但它是存在的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35178836/