現在、パッケージのアイコンを取得して、このコードで imageView に設定しようとしています。ai はドローアブルです。
final PackageManager pm = getPackageManager();
try {
ai = pm.getApplicationIcon(packageName);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bitmap = ((BitmapDrawable)ai).getBitmap();
Log.i("Icons Drawable", ai.toString());
Log.i("Icons Bitmap", bitmap.toString());
imageView.setImageBitmap(bitmap);
Logcat の出力:
11-06 11:10:22.785: I/Icons Drawable(20017): android.graphics.drawable.BitmapDrawable@416184f0
11-06 11:10:22.785: I/Icons Bitmap(20017): android.graphics.Bitmap@41618488
11-06 11:10:22.790: E/AndroidRuntime(20017): FATAL EXCEPTION: main
11-06 11:10:22.790: E/AndroidRuntime(20017): java.lang.RuntimeException: Unable to start activity : java.lang.NullPointerException
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1973)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1999)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.ActivityThread.access$600(ActivityThread.java:127)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.os.Looper.loop(Looper.java:137)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.ActivityThread.main(ActivityThread.java:4513)
11-06 11:10:22.790: E/AndroidRuntime(20017): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 11:10:22.790: E/AndroidRuntime(20017): at java.lang.reflect.Method.invoke(Method.java:511)
11-06 11:10:22.790: E/AndroidRuntime(20017): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:974)
11-06 11:10:22.790: E/AndroidRuntime(20017): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:741)
11-06 11:10:22.790: E/AndroidRuntime(20017): at dalvik.system.NativeStart.main(Native Method)
11-06 11:10:22.790: E/AndroidRuntime(20017): Caused by: java.lang.NullPointerException
11-06 11:10:22.790: E/AndroidRuntime(20017): at com.analyze.project.MalwareAlertDialog.onCreate(MalwareAlertDialog.java:98)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.Activity.performCreate(Activity.java:4465)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
11-06 11:10:22.790: E/AndroidRuntime(20017): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
11-06 11:10:22.790: E/AndroidRuntime(20017): ... 11 more
Drawable を imageView に直接設定しようとしても機能しません
imageView.setImageDrawable(ai);