0

![在此处输入图像描述][1]我在 logcat 中遇到以下错误。该应用程序在 Android 模拟器上启动,然后在尝试加载初始屏幕时立即崩溃。具体来说,logcat 指出它存在:

Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: assets/Images/Splash.png (Internal)

下面是完整的 logcat 条目和我的资产文件结构的文件结构的图像。非常感谢任何所有建议。

04-28 15:47:04.105: E/AndroidRuntime(2527): FATAL EXCEPTION: GLThread 162
04-28 15:47:04.105: E/AndroidRuntime(2527): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/Images/Splash.png
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.me.mygdxgame.Splash.show(Splash.java:66)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.Game.setScreen(Game.java:62)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.me.mygdxgame.SimpleBike.create(SimpleBike.java:111)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:292)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
04-28 15:47:04.105: E/AndroidRuntime(2527): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: assets/Images/Splash.png (Internal)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:73)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:580)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.backends.android.AndroidFileHandle.length(AndroidFileHandle.java:155)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:215)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
04-28 15:47:04.105: E/AndroidRuntime(2527):     ... 11 more
04-28 15:47:04.105: E/AndroidRuntime(2527): Caused by: java.io.FileNotFoundException: assets/Images/Splash.png
04-28 15:47:04.105: E/AndroidRuntime(2527):     at android.content.res.AssetManager.openAsset(Native Method)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at android.content.res.AssetManager.open(AssetManager.java:315)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at android.content.res.AssetManager.open(AssetManager.java:289)
04-28 15:47:04.105: E/AndroidRuntime(2527):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:71)
04-28 15:47:04.105: E/AndroidRuntime(2527):     ... 15 more
04-28 15:47:04.165: I/AndroidInput(2527): sensor listener tear down
04-28 15:47:04.165: I/AndroidGraphics(2527): Managed meshes/app: { }
04-28 15:47:04.165: I/AndroidGraphics(2527): Managed textures/app: { }
04-28 15:47:04.165: I/AndroidGraphics(2527): Managed shaders/app: { }
04-28 15:47:04.165: I/AndroidGraphics(2527): Managed buffers/app: { }
04-28 15:47:08.845: I/Process(2527): Sending signal. PID: 2527 SIG: 9
4

1 回答 1

3

经过一番谷歌搜索后,我意识到解决方案是更改文件路径。Android 路径是相对于 assets 文件夹的,而 Desktop 使用的是相对于根文件夹的路径。我只需要从文件路径中删除“assets/”,它就起作用了。

于 2013-05-25T14:18:54.450 回答