每当我在模拟器上运行我的应用程序时,我在unbindDrawables中得到NullPointerException
这是我在MainActivity中使用的代码:
@Override
protected void onDestroy()
{
super.onDestroy();
unbindDrawables(findViewById(R.id.rootView));
System.gc();
}
/**
* Not used for now but useful if any bitmap based drawable will be added
* @param view
*/
private void unbindDrawables(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
这是logcat
02-27 23:41:41.034: D/MainActivity(1365): chartBoost for more buttons
02-27 23:41:41.034: D/AndroidRuntime(1365): Shutting down VM
02-27 23:41:41.038: W/dalvikvm(1365): threadid=1: thread exiting with uncaught exception (group=0xa617e908)
02-27 23:41:41.050: E/AndroidRuntime(1365): FATAL EXCEPTION: main
02-27 23:41:41.050: E/AndroidRuntime(1365): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bomsn.fitnessquiz/com.bomsn.fitnessquiz.MainActivity}: java.lang.NullPointerException
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.os.Looper.loop(Looper.java:137)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.ActivityThread.main(ActivityThread.java:5041)
02-27 23:41:41.050: E/AndroidRuntime(1365): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 23:41:41.050: E/AndroidRuntime(1365): at java.lang.reflect.Method.invoke(Method.java:511)
02-27 23:41:41.050: E/AndroidRuntime(1365): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-27 23:41:41.050: E/AndroidRuntime(1365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-27 23:41:41.050: E/AndroidRuntime(1365): at dalvik.system.NativeStart.main(Native Method)
02-27 23:41:41.050: E/AndroidRuntime(1365): Caused by: java.lang.NullPointerException
02-27 23:41:41.050: E/AndroidRuntime(1365): at com.bomsn.fitnessquiz.MainActivity.onCreate(MainActivity.java:168)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.Activity.performCreate(Activity.java:5104)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-27 23:41:41.050: E/AndroidRuntime(1365): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-27 23:41:41.050: E/AndroidRuntime(1365): ... 11 more
02-27 23:41:42.886: D/Volley(1365): [119] u.a: HTTP response for request=<[ ] https://live.chartboost.com/api/config 0x64ca17da HIGH 1> [lifetime=3152], [size=404], [rc=200], [retryCount=0]
在我向xml文件添加更多drawable之前,它没有问题。