2

次のことをしようとすると、このエラーが発生します。

File file = new File(cacheDir, fileName);
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());

キャッシュディレクトリは次のものからです:

context.getCacheDir();

エラーは次のとおりです。

11-30 12:38:34.029: E/BitmapFactory(18814): ストリームをデコードできません: java.io.FileNotFoundException: /data/data/com.android.test/cache/file_name: オープンに失敗しました: ENOENT (そのようなファイルはありません)またはディレクトリ)

これは、ファイルを書き込むための私のボイドです:

public static void writeFile(Bitmap bmp, File f) {
        if (bmp == null)
            return;

        FileOutputStream out = null;

        try {
            out = new FileOutputStream(f);
            bmp.compress(Bitmap.CompressFormat.PNG, 80, out);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (out != null)
                    out.close();
            } catch (Exception ex) {
            }
        }
        Log.i("app", "path: "+f.getAbsolutePath());
    }

この void では、最後に Log.i がエラー ファイルと同じファイル パスを出力します。

このエラーは、Android 4.2 を搭載したデバイスでのみ発生します。Android 4.1.xまではすべて正常に動作します。

4

0 に答える 0