【问题标题】:GdxRuntimeException: Couldn't load fileGdxRuntimeException:无法加载文件
【发布时间】:2011-12-08 10:29:09
【问题描述】:

我正在关注 libgdx 上的 this 教程。我想做的是从 badlogic.jpg 的副本中加载纹理(副本称为 wawa.jpg):

public class HelloWorld implements ApplicationListener {
    SpriteBatch spriteBatch;
    Texture texture;
    Texture watched_texture;
    BitmapFont font;
    Vector2 textPosition = new Vector2(100, 100);
    Vector2 textDirection = new Vector2(5, 3);

    @Override
    public void create () {
        font = new BitmapFont();
        font.setColor(Color.RED);
        texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
        watched_texture = new Texture(Gdx.files.internal("data/wawa.jpg"));
        spriteBatch = new SpriteBatch();
    }
...

我得到的是应用程序崩溃和调试中的“com.badlogic.gdx.utils.GdxRuntimeException:无法加载文件数据/wawa.jpg”:

10-18 09:24:45.383: WARN/dalvikvm(330): threadid=9: 线程以未捕获的异常退出(组=0x40015560) 10-18 09:24:45.502:错误/AndroidRuntime(330):致命异常:GLThread 10 10-18 09:24:45.502: 错误/AndroidRuntime(330): com.badlogic.gdx.utils.GdxRuntimeException: 无法加载文件'wawa.jpg' 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:135) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.graphics.Texture.(Texture.java:126) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.graphics.Texture.(Texture.java:104) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.test.myfirsttriangle.MyFirstTriangle.create(MyFirstTriangle.java:29) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceCreated(AndroidGraphics.java:284) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118) 10-18 09:24:45.502:错误/AndroidRuntime(330):原因:com.badlogic.gdx.utils.GdxRuntimeException:读取文件时出错:data/wawa.jpg(内部) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:64) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:132) 10-18 09:24:45.502: 错误/AndroidRuntime(330): ... 还有 6 个 10-18 09:24:45.502: 错误/AndroidRuntime(330): 原因: java.io.FileNotFoundException: data/wawa.jpg 10-18 09:24:45.502:错误/AndroidRuntime(330):在 android.content.res.AssetManager.openAsset(本机方法) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 android.content.res.AssetManager.open(AssetManager.java:314) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 android.content.res.AssetManager.open(AssetManager.java:288) 10-18 09:24:45.502: 错误/AndroidRuntime(330): 在 com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:62) 10-18 09:24:45.502: 错误/AndroidRuntime(330): ... 还有 7 个

就是想不通怎么回事。

【问题讨论】:

  • 请将您的解决方案作为答案并选择它。这将使人们更容易找到需要答案的问题。见stackoverflow.com/faq#howtoask。 (完全可以回答您自己的问题。:)

标签: android libgdx


【解决方案1】:

我也有同样的问题,但我的错误是文件名错误。

该文件名为 gameScreenshot.PNG,我输入的字符串为“gameScreenshot.png”。

在 Windows 中它接受文件名很好,但在 android 上它不起作用,所以我不得不将它重命名为“gameScreenshot.PNG”

【讨论】:

    【解决方案2】:

    已解决:我没有将新纹理放入android项目的“assets”文件夹中

    【讨论】:

    • 我也遇到过一件事。如果通过文件系统将asset文件放到文件夹中,一定要在eclipse中刷新文件夹。
    • 这让我大吃一惊——我把它放在 res/drawable-... 文件夹中(就像我通常对 andorid 上的图像所做的那样)
    猜你喜欢
    • 2013-05-10
    • 2017-07-17
    • 2013-05-17
    • 2013-07-20
    • 1970-01-01
    • 2017-05-17
    • 2013-10-19
    • 2016-09-10
    相关资源
    最近更新 更多