Ich benutze Android 2.1 und möchte eine Zurück-Schaltfläche zu einer MapsAvtivity hinzufügen. Ich habe versucht, was auf dieser Seite [Display back button on action bar aber die Anwendung abstürzt. Ich habe ersetzt Fragment erweitertActivity mit AppCompatActivity wie in einem anderen Forum empfohlen wurde, aber die Anwendung noch abstürzt. Ich weiß, dass es etwas mit der Aktionsleiste zu tun hat, denn wenn ich es entferne, funktioniert die Anwendung. Es scheint, dass die Aktionsleiste null ist. Ich stecke fest und habe die Bewerbung mehrmals gestartet. Hier ist der Fehler:Hinzufügen einer Zurück-Schaltfläche Aktivität
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pc.canda.theplacestosee/com.pc.canda.theplacestosee.MapsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at com.pc.canda.theplacestosee.MapsActivity.onCreate(MapsActivity.java:31)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694
Können Sie den Code in Ihrer onCreate-Methode veröffentlichen? – Jay
Welches Thema wird verwendet? Hat es ActionBar? – user35603
Bitte poste 'MapsActivity.onCreate()', Manifest file und styles.xml. –