我有一个应用程序,当我在桌面上运行它时,资产很好并且运行正常但是当我尝试在Android(模拟器或设备上的apk)上运行它时它强制关闭并且我得到了日志cat错误:
11-08 15:37:04.556: E/AndroidRuntime(1187): FATAL EXCEPTION: GLThread 90
11-08 15:37:04.556: E/AndroidRuntime(1187): Process: com.mkgame.game1.android, PID: 1187
11-08 15:37:04.556: E/AndroidRuntime(1187): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/playButton2.png
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.MKgames.game1.screen.MainMenuScreen.<init>(MainMenuScreen.java:38)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.MKgames.Game1.create(Game1.java:29)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
11-08 15:37:04.556: E/AndroidRuntime(1187): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
11-08 15:37:04.556: E/AndroidRuntime(1187): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
11-08 15:37:04.556: E/AndroidRuntime(1187): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: data/playButton2.png (Internal)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
11-08 15:37:04.556: E/AndroidRuntime(1187): ... 10 more
11-08 15:37:04.556: E/AndroidRuntime(1187): Caused by: java.io.FileNotFoundException: data/playButton2.png
11-08 15:37:04.556: E/AndroidRuntime(1187): at android.content.res.AssetManager.openAsset(Native Method)
11-08 15:37:04.556: E/AndroidRuntime(1187): at android.content.res.AssetManager.open(AssetManager.java:316)
11-08 15:37:04.556: E/AndroidRuntime(1187): at android.content.res.AssetManager.open(AssetManager.java:290)
11-08 15:37:04.556: E/AndroidRuntime(1187): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
11-08 15:37:04.556: E/AndroidRuntime(1187): ... 12 more
Herre是我设置资产的地方:
Texture playButtonTxture = new Texture(Gdx.files.internal("data/playButton2.png"));
我查看过许多其他类似主题的主题,并尝试过以下方法:
在资产下创建数据文件夹 刷新日食探险家 项目&gt;清洁 刷新项目的重要性 三重检查文件路径 重新启动IDE 从资产名称中移除大写(这是一个神话还是一个行为问题?)
资产位于android资产下的数据文件夹中,名称正确,我已经尝试了多种不同的解决方案组合。
注意 - 如果我要移除此资产并继续前进,我相信我会在下一个资产上遇到同样的错误。
当我尝试使用小写断言名称并更改android / asset / data文件夹和游戏中的资产名称时,我得到了同样的错误:
11-09 13:51:50.623: E/AndroidRuntime(1118): FATAL EXCEPTION: GLThread 81
11-09 13:51:50.623: E/AndroidRuntime(1118): Process: com.mkgame.game1.android, PID: 1118
11-09 13:51:50.623: E/AndroidRuntime(1118): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/play_button2.png
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.MKgames.game1.screen.MainMenuScreen.<init>(MainMenuScreen.java:38)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.MKgames.Game1.create(Game1.java:29)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
11-09 13:51:50.623: E/AndroidRuntime(1118): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
11-09 13:51:50.623: E/AndroidRuntime(1118): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
11-09 13:51:50.623: E/AndroidRuntime(1118): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: data/play_button2.png (Internal)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
11-09 13:51:50.623: E/AndroidRuntime(1118): ... 10 more
11-09 13:51:50.623: E/AndroidRuntime(1118): Caused by: java.io.FileNotFoundException: data/play_button2.png
11-09 13:51:50.623: E/AndroidRuntime(1118): at android.content.res.AssetManager.openAsset(Native Method)
11-09 13:51:50.623: E/AndroidRuntime(1118): at android.content.res.AssetManager.open(AssetManager.java:316)
11-09 13:51:50.623: E/AndroidRuntime(1118): at android.content.res.AssetManager.open(AssetManager.java:290)
11-09 13:51:50.623: E/AndroidRuntime(1118): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
11-09 13:51:50.623: E/AndroidRuntime(1118): ... 12 more
答案 0 :(得分:0)
当我以错误的方式实施Google Play服务库时,我遇到了类似的问题。 它还包含一个assets-folder,我的Android项目以某种方式链接到该文件夹。
因此,如果您已实施Google Play服务,请尝试将其删除,看看是否有效。 然后以正确的方式将其添加到项目中。
希望这有帮助!