Wie bekomme ich die ActionBar von Main(ActionBarActivity) Absicht Aktivität
Benutze ich ActionBarActivity Absicht, eine neue Aktivität
aber ich kann nicht anrufen ActionBar-Methode in der Activity
// requestWindowFeature(Window.FEATURE_ACTION_BAR);
// getActionBar().setTitle("123");
ActionBar actionBar =getActionBar();
//
actionBar.setDisplayHomeAsUpEnabled(true);
erhalten null
01-14 16:29:58.712 3405-3405/com.fragment.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.fragment.test, PID: 3405
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fragment.test/com.fragment.test.Ac1}: 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.fragment.test.Ac1.onCreate(Ac1.java:15)
at android.app.Activity.performCreate(Activity.java:5933)
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)
01-14 16:30:01.233 3405-3405/com.fragment.test I/Process﹕ Sending signal. PID: 3405 SIG: 9
01-14 17:12:11.968 3795-3795/com.fragment.test I/Process﹕ Sending signal. PID: 3795 SIG: 9
Bekomme ich die ActionBar, die ohne änderung der Aktivität zu ActionBarActivity
Dank
InformationsquelleAutor Ymow Wu | 2015-01-14
Schreibe einen Kommentar Antworten abbrechen
Du musst angemeldet sein, um einen Kommentar abzugeben.
wenn Sie SUPPORT LIBRARY ► android.Unterstützung.v7.app.ActionBar
haben Sie um die Unterstützung zu bekommen ActionBar.
so,
so, können Sie Titel, Untertitel und andere Funktionen (alle sehen, klicken Sie ►HIER◄)
Wie:
und Wenn ich importieren android.app.ActionBar; ActionBar actionBar = getActionBar(); actionBar.setTitle("Meine App-Titel"); erhalten null 'void android.Unterstützung.v7.- widget.Toolbar.setTitle(java.lang.CharSequence)' auf ein null-Objekt Verweis
post alle Aktivitäten code bitte.
Ihre Tätigkeit erstreckt sich ActionBar oder ActionBarActivity ???
Ich nicht, weil die Klasse erweitern Aktivität, die ich ändern, zu erweitern ActionBarActivity und es funktioniert.
InformationsquelleAutor Guihgo
Oder direkt können Sie,
und andere Methoden...
InformationsquelleAutor Talayhan
Verwenden Sie die support-Methode:
InformationsquelleAutor Simas
Ändern Sie die Tätigkeit erstreckt sich ActionBarActivity und es ist eine Arbeit
InformationsquelleAutor Ymow Wu
InformationsquelleAutor sellmaurer