這一件事是讓我回來..應用程序崩潰,只要它啓動,logcat指向以下引起的問題(2nd線下):java.lang.NullPointerException試圖啓用動作欄應用程序圖標,並將其作爲切換按鈕
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
}
}
的logcat:
12-11 01:25:51.852 10780-10780/com.example.paul.amityhealth W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41979c98)
12-11 01:25:51.852 10780-10780/com.example.paul.amityhealth W/dalvikvm﹕ threadid=1: uncaught exception occurred
12-11 01:25:51.853 10780-10780/com.example.paul.amityhealth W/System.err﹕ java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.paul.amityhealth/com.example.paul.amityhealth.MainActivity}: java.lang.NullPointerException
12-11 01:25:51.855 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
12-11 01:25:51.856 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
12-11 01:25:51.857 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:155)
12-11 01:25:51.858 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
12-11 01:25:51.859 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:110)
12-11 01:25:51.860 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.os.Looper.loop(Looper.java:193)
12-11 01:25:51.860 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5388)
12-11 01:25:51.861 10780-10780/com.example.paul.amityhealth W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
12-11 01:25:51.862 10780-10780/com.example.paul.amityhealth W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
12-11 01:25:51.863 10780-10780/com.example.paul.amityhealth W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-11 01:25:51.863 10780-10780/com.example.paul.amityhealth W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:655)
12-11 01:25:51.865 10780-10780/com.example.paul.amityhealth W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
12-11 01:25:51.866 10780-10780/com.example.paul.amityhealth W/System.err﹕ Caused by: java.lang.NullPointerException
12-11 01:25:51.868 10780-10780/com.example.paul.amityhealth W/System.err﹕ at com.example.paul.amityhealth.MainActivity.onCreate(MainActivity.java:86)
12-11 01:25:51.869 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5280)
12-11 01:25:51.870 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
12-11 01:25:51.871 10780-10780/com.example.paul.amityhealth W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
12-11 01:25:51.872 10780-10780/com.example.paul.amityhealth W/System.err﹕ ... 11 more
12-11 01:25:51.872 10780-10780/com.example.paul.amityhealth W/dalvikvm﹕ threadid=1: calling UncaughtExceptionHandler
12-11 01:25:51.884 10780-10780/com.example.paul.amityhealth E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.paul.amityhealth, PID: 10780
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.paul.amityhealth/com.example.paul.amityhealth.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5388)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:655)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.paul.amityhealth.MainActivity.onCreate(MainActivity.java:86)
at android.app.Activity.performCreate(Activity.java:5280)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5388)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:655)
at dalvik.system.NativeStart.main(Native Method)
我試圖改變爲假,不工作要麼。即使消除這兩條線也沒有幫助,我找不到答案。我是一個相對較新的開發人員,所以如果你的回答簡單易懂,歡呼!
編輯:添加斷點後,該顯示:
this = {[email protected]}
savedInstanceState = null
mDrawerList = {[email protected]}"android.widget.ListView{426f0490 VFED.VC. ......I. 0,0-0,0 #7f090041 app:id/list_slidermenu}"
adapter = {[email protected]}
mDrawerToggle = null
解決:
我增加了以下內容清單文件:
android:theme="@android:style/Theme.Holo.Light"
感謝您的支持!
您是否嘗試過在getActionBar()中設置斷點?這聽起來像它正在返回'null'。 – 2014-12-10 21:42:59
添加到代碼的頂部。你是對的,這是'空' – 2014-12-10 22:03:38
我完全失去了如何解決這個問題。 :( – 2014-12-10 22:04:54