ActionBar.setDisplayHomeAsUpEnabled (true); Android app crash when using Android Studio

I recently upgraded from Eclipse to Android Studio ...

I imported my app to android studio and when I try to run my app via ADB my app crashes.

I removed actionBar.setDisplayHomeAsUpEnabled (true); Out of activity, and this activity does not crash ..

I didn't encounter this error when using Eclipse ...

Here is the Logcat log:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.test/com.test.test.MainActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
        at android.app.ActivityThread.access$600(ActivityThread.java:156)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:5299)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at com.test.test.MainActivity.onCreate(MainActivity.java:33)
        at android.app.Activity.performCreate(Activity.java:5122)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)

      

On the 33rd line in the main activity I am setting setDisplayHomeAsUpEnabled To True ..

And the MainActivity theme is not set to Theme.NoTitleBar ...

Edit: I tried to import other applications, but I got the same error ... All applications working with Eclipse ..

Edit: Code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true); // Line 33

      

+3


source to share





All Articles