5

サンプル ソース: http://developer.android.com/training/displaying-bitmaps/index.html

プロジェクトをまったく実行できない理由がわかりません。

丸太の猫

09-06 13:14:13.664: E/AndroidRuntime(591): FATAL EXCEPTION: main
09-06 13:14:13.664: E/AndroidRuntime(591): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.bitmapfun/com.example.android.bitmapfun.ui.ImageGridActivity}: java.lang.NullPointerException
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.os.Looper.loop(Looper.java:137)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.ActivityThread.main(ActivityThread.java:4340)
09-06 13:14:13.664: E/AndroidRuntime(591):  at java.lang.reflect.Method.invokeNative(Native Method)
09-06 13:14:13.664: E/AndroidRuntime(591):  at java.lang.reflect.Method.invoke(Method.java:511)
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-06 13:14:13.664: E/AndroidRuntime(591):  at dalvik.system.NativeStart.main(Native Method)
09-06 13:14:13.664: E/AndroidRuntime(591): Caused by: java.lang.NullPointerException
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.example.android.bitmapfun.util.DiskLruCache.getDiskCacheDir(DiskLruCache.java:268)
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.example.android.bitmapfun.util.ImageCache.init(ImageCache.java:121)
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.example.android.bitmapfun.util.ImageCache.<init>(ImageCache.java:61)
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.example.android.bitmapfun.util.ImageCache.findOrCreateCache(ImageCache.java:107)
09-06 13:14:13.664: E/AndroidRuntime(591):  at com.example.android.bitmapfun.ui.ImageGridFragment.onCreate(ImageGridFragment.java:96)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:834)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.Activity.performStart(Activity.java:4475)
09-06 13:14:13.664: E/AndroidRuntime(591):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)
09-06 13:14:13.664: E/AndroidRuntime(591):  ... 11 more
4

2 に答える 2

1

おそらくキーとして null を渡しています。これらの変更を使用してコードを確認できます。

public static String hashKeyForDisk(String key) {
    String cacheKey;
    try {
        final MessageDigest mDigest = MessageDigest.getInstance("MD5");
        if (key == null) {
            Log.e("TEST","key = null");
            throw new IllegalArgumentException(" key == null");
        }

        if (mDigest == null) {
            Log.e("TEST","mDigest = null");

            return String.valueOf(key.hashCode());
        }
        byte[] bytes = key.getBytes();
        mDigest.update(bytes);
        cacheKey = bytesToHexString(mDigest.digest());
    } catch (NoSuchAlgorithmException e) {
        cacheKey = String.valueOf(key.hashCode());
    }
    return cacheKey;
}
于 2013-10-16T09:12:09.823 に答える