1

I'm trying to access data from my application's data directory. I'm able to load default.fnt file, but then it tells me the associated default.png cannot be found. How can I get the system to recognize the file? Is there something I've setup incorrectly?

Exception

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

File Permissions

I have checked that the files exist and that they have the right owner/group and even set the permissions to 777 just to test.

Shell Screen Shot

I've seen several other questions where the problem was with the assets folder in the projects, but I'm not using the assets folder. And the code is able to find the .fnt file sitting next to the .png.


Font Definition Header

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


In case it helps, here is the code I use to get the file handles:

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();
}

P.S. The font file and png worked when they were in the assets folder. So I'm assuming they are setup properly.

4

1 に答える 1

2

FileNotFoundから例外が発生していますandroid.content.res.AssetManager.openが、そのドキュメントには、「アセットとしてバンドルされたファイル」でのみ機能すると明示的に記載されています。

ただし、それを直接呼び出すことはありません....

ああ、Libgdx BitmapFont コンストラクターGdx.files.internalは、フォント テクスチャを読み込むために使用します。

public BitmapFont (BitmapFontData data, TextureRegion region, boolean integer) {
        this.region = region == null ? new TextureRegion(new Texture(Gdx.files.internal(data.imagePath), false)) : region;
        ...

(フォントテクスチャファイルが「内部」であると仮定するのはLibgdxのバグのようですが、それをどのように回避すべきかわかりません...)

メソッドで明示的なテクスチャ ファイルを受け取るコンストラクタを呼び出すことで、BitmapFontこれを回避できると思いますloadFonts

于 2013-07-07T23:09:35.490 に答える