FileNotFoundException异常的Andr​​oid logcat的错误 [英] FileNotFoundException Android logcat errors

查看:182
本文介绍了FileNotFoundException异常的Andr​​oid logcat的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的游戏运行正常,当我测试的桌面版本,但是当我推出一个Android模拟器,并并尝试在模拟器游戏关闭运行的游戏,我得到了logcat的错误:

  8月10号至28号:00:53.528:E / AndroidRuntime(1203):致命异常:GLThread 84
八月10日至28日:00:53.528:E / AndroidRuntime(1203):工艺:com.mkgame.game1.android,PID:1203
八月10日至28日:00:53.528:E / AndroidRuntime(1203):com.badlogic.gdx.utils.GdxRuntimeException:无法加载文件:playButton2.png
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.Pixmap< INIT>(Pixmap.java:140)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.glutils.FileTextureData prepare(FileTextureData.java:64)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.Texture< INIT>(Texture.java:121)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.Texture< INIT>(Texture.java:100)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.Texture< INIT>(Texture.java:92)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.MKgames.game1.screen.MainMenuScreen< INIT>(MainMenuScreen.java:38)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.MKgames.Game1.create(Game1.java:29)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在android.opengl.GLSurfaceView $ GLThread.guardedRun(GLSurfaceView.java:1512)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在android.opengl.GLSurfaceView $ GLThread.run(GLSurfaceView.java:1240)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):com.badlogic.gdx.utils.GdxRuntimeException:产生的原因读取文件时出错:playButton2.png(内部)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.graphics.Pixmap< INIT>(Pixmap.java:137)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):10 ...更多
八月10日至28日:00:53.528:E / AndroidRuntime(1203):java.io.FileNotFoundException:产生的原因playButton2.png
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在android.content.res.AssetManager.openAsset(本机方法)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在android.content.res.AssetManager.open(AssetManager.java:316)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在android.content.res.AssetManager.open(AssetManager.java:290)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):在com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
八月10日至28日:00:53.528:E / AndroidRuntime(1203):12 ...更多
 

我的理解是错误migh是显而易见的,没有找到该文件,但它应该是因为它的位置就可以了,当我运行它作为一个桌面应用程序的文件是好的(我复制了所有我的桌面资产注入机器人资产,它们有完全一样的)。但是,是什么问题呢?

下面是我设置图像:

 纹理playButtonTxture =新的纹理(Gdx.files.internal(playButton2.png));
 

解决方案

您应该看看这里并遵循以下说明:的 https://github.com/libgdx/libgdx/wiki/Manual-project-setup#asset-folder-setup

  

Android的项目有一个名为资产的子文件夹,它会自动创建。提供给Android应用程序文件必须放在这里。这是有问题的,因为这些相同的文件必须可用到桌面的应用程序。而不是维护所有文件的两个副本,桌面项目应配置查找资产在Android项目[...]

My game runs correctly when I test the desktop version, but when I launch an android emulator and and try to run the game on the emulator the game closes and I get the logcat errors:

10-28 08:00:53.528: E/AndroidRuntime(1203): FATAL EXCEPTION: GLThread 84
10-28 08:00:53.528: E/AndroidRuntime(1203): Process: com.mkgame.game1.android, PID: 1203
10-28 08:00:53.528: E/AndroidRuntime(1203): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: playButton2.png
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.load(Texture.java:130)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:92)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.MKgames.game1.screen.MainMenuScreen.<init>(MainMenuScreen.java:38)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.MKgames.Game1.create(Game1.java:29)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
10-28 08:00:53.528: E/AndroidRuntime(1203): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: playButton2.png (Internal)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
10-28 08:00:53.528: E/AndroidRuntime(1203):     ... 10 more
10-28 08:00:53.528: E/AndroidRuntime(1203): Caused by: java.io.FileNotFoundException: playButton2.png
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.content.res.AssetManager.openAsset(Native Method)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.content.res.AssetManager.open(AssetManager.java:316)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at android.content.res.AssetManager.open(AssetManager.java:290)
10-28 08:00:53.528: E/AndroidRuntime(1203):     at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
10-28 08:00:53.528: E/AndroidRuntime(1203):     ... 12 more

I understand that the error migh be obvious that the file is not found, but it should be as it's location is fine and when i run it as a desktop app the file is fine (I copied all of my desktop assets into the android assets, they there are exactly the same). So what could the problem be?

Here is where i set the image:

Texture playButtonTxture = new Texture(Gdx.files.internal("playButton2.png"));

解决方案

You should take a look here and follow these instructions : https://github.com/libgdx/libgdx/wiki/Manual-project-setup#asset-folder-setup

The Android project has a subfolder named assets, which is created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the desktop application. Rather than maintain two copies of all the files, the desktop project should be configured to find the assets in the Android project [...]

这篇关于FileNotFoundException异常的Andr​​oid logcat的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆