我正在尝试从我的应用程序的数据目录中访问数据。我能够加载default.fnt
文件,但它告诉我default.png
无法找到相关联的文件。如何让系统识别文件?有什么我设置不正确的吗?
例外
07-07 22:22:52.467: E/AndroidRuntime(10785): FATAL EXCEPTION: GLThread 240
07-07 22:22:52.467: E/AndroidRuntime(10785): com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: /data/data/com.iliadonline.client/files/data/gfx/fonts/default.png
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:126)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:125)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.g2d.BitmapFont.<init>(BitmapFont.java:99)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.iliadonline.client.render.Render.loadFonts(Render.java:213)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.iliadonline.client.render.Render.<init>(Render.java:71)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.iliadonline.client.IliadClient.create(IliadClient.java:65)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:322)
07-07 22:22:52.467: E/AndroidRuntime(10785): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
07-07 22:22:52.467: E/AndroidRuntime(10785): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
07-07 22:22:52.467: E/AndroidRuntime(10785): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: /data/data/com.iliadonline.client/files/data/gfx/fonts/default.png (Internal)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:74)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:224)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
07-07 22:22:52.467: E/AndroidRuntime(10785): ... 13 more
07-07 22:22:52.467: E/AndroidRuntime(10785): Caused by: java.io.FileNotFoundException: /data/data/com.iliadonline.client/files/data/gfx/fonts/default.png
07-07 22:22:52.467: E/AndroidRuntime(10785): at android.content.res.AssetManager.openAsset(Native Method)
07-07 22:22:52.467: E/AndroidRuntime(10785): at android.content.res.AssetManager.open(AssetManager.java:315)
07-07 22:22:52.467: E/AndroidRuntime(10785): at android.content.res.AssetManager.open(AssetManager.java:289)
07-07 22:22:52.467: E/AndroidRuntime(10785): at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:72)
07-07 22:22:52.467: E/AndroidRuntime(10785): ... 15 more
文件权限
我检查了文件是否存在并且它们具有正确的所有者/组,甚至将权限设置为 777 只是为了测试。
我已经看到了其他几个问题,问题出在项目中的assets文件夹上,但我没有使用 assets 文件夹。并且代码能够找到位于 .png 旁边的 .fnt 文件。
字体定义标题
info face="Droid Sans" size=17 bold=0 italic=0 charset="" unicode=0 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=1,1 common lineHeight=20 base=18 scaleW=256 scaleH=128 pages=1 packed=0 page id=0 file="default.png" chars count=95
如果有帮助,这是我用来获取文件句柄的代码:
FileHandle dataDir = Gdx.files.local("data");
FileHandle gfxDir = dataDir.child("gfx");
if(!gfxDir.isDirectory())
{
//mkdirs will make all directories, so this includes the "data" dir
gfxDir.mkdirs();
}
FileHandle spritesDir = gfxDir.child("sprites");
if(!spritesDir.isDirectory())
{
spritesDir.mkdirs();
}
FileHandle fontsDir = gfxDir.child("fonts");
if(!fontsDir.isDirectory())
{
fontsDir.mkdirs();
}
PS字体文件和png在资产文件夹中时可以使用。所以我假设它们设置正确。