GdxRuntimeException:无法加载文件

发布于 2024-12-10 06:10:08 字数 3109 浏览 0 评论 0原文

我正在关注关于 libgdx 的教程。我想做的是从 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:无法加载文件 data/wawa.jpg" 调试中:

10-18 09:24:45.383: WARN/dalvikvm(330): threadid=9: thread exiting with uncaught exception (group=0x40015560)
10-18 09:24:45.502: ERROR/AndroidRuntime(330): FATAL EXCEPTION: GLThread 10
10-18 09:24:45.502: ERROR/AndroidRuntime(330): com.badlogic.gdx.utils.GdxRuntimeException: couldn't load file 'wawa.jpg'
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:135)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Texture.(Texture.java:126)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Texture.(Texture.java:104)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.test.myfirsttriangle.MyFirstTriangle.create(MyFirstTriangle.java:29)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceCreated(AndroidGraphics.java:284)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
10-18 09:24:45.502: ERROR/AndroidRuntime(330): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: data/wawa.jpg (Internal)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:64)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:132)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     ... 6 more
10-18 09:24:45.502: ERROR/AndroidRuntime(330): Caused by: java.io.FileNotFoundException: data/wawa.jpg
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.openAsset(Native Method)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.open(AssetManager.java:314)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.open(AssetManager.java:288)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:62)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     ... 7 more

只是无法弄清楚出了什么问题。

I am following this tutorial on libgdx. What i am trying to do is loading a texture from a copy of badlogic.jpg (copy is called 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();
    }
...

What i get is the crash of application and "com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file data/wawa.jpg" in debug:

10-18 09:24:45.383: WARN/dalvikvm(330): threadid=9: thread exiting with uncaught exception (group=0x40015560)
10-18 09:24:45.502: ERROR/AndroidRuntime(330): FATAL EXCEPTION: GLThread 10
10-18 09:24:45.502: ERROR/AndroidRuntime(330): com.badlogic.gdx.utils.GdxRuntimeException: couldn't load file 'wawa.jpg'
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:135)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Texture.(Texture.java:126)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Texture.(Texture.java:104)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.test.myfirsttriangle.MyFirstTriangle.create(MyFirstTriangle.java:29)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceCreated(AndroidGraphics.java:284)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
10-18 09:24:45.502: ERROR/AndroidRuntime(330): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: data/wawa.jpg (Internal)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:64)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:132)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     ... 6 more
10-18 09:24:45.502: ERROR/AndroidRuntime(330): Caused by: java.io.FileNotFoundException: data/wawa.jpg
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.openAsset(Native Method)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.open(AssetManager.java:314)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at android.content.res.AssetManager.open(AssetManager.java:288)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:62)
10-18 09:24:45.502: ERROR/AndroidRuntime(330):     ... 7 more

Just can't figure out what's wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新一帅帅 2024-12-17 06:10:08

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

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

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

I also had the same problem, but my mistake was a file name error.

The file was called gameScreenshot.PNG, and I had put in the string as "gameScreenshot.png".

In Windows it accepted the file name fine, but on android it didn't work, so I had to rename it to "gameScreenshot.PNG"

娇俏 2024-12-17 06:10:08

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

solved: i didn't put the new texture into the "assets" folder of android project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文