读取文件Libgdx RunTime异常时出错

时间:2013-05-25 01:50:45

标签: java android libgdx

![在此处输入图像描述] [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

1 个答案:

答案 0 :(得分:3)

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