java - 读取文件 Libgdx 运行时异常时出错

标签 java android libgdx

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

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

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

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

最佳答案

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

关于java - 读取文件 Libgdx 运行时异常时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16745664/

相关文章:

android - TangoSupport_detectCorners 参数 "point_of_interest"

android - 如何创建类似卡片的android样式 ListView

java - LibGDX:如何绘制透明多边形?

android - 错误 :Configuration with name 'default' not found when trying to import project as library into Android Studio

java - 图像从一侧移动到另一侧

gradle - libgdx一段时间后无法加载纹理

java - 重新加载 JinternalFrame Java

java - 为什么我无法从该数组输出数据?

java - 下载的文件有 0 字节

java - Spring MVC : Not able to connect to Rest service