0

I created an Activity to test some stuff called Parse. I have tried to start it activity 5 times. I've recreated the activity with different name, rewrote the Intent stuff and changed the button that runs the code. All the trys faild.

This is my code:

    Intent intent = new Intent(Login.this,Parse.class);
    startActivity(intent);

I get the following LogCat:

    11-10 10:26:27.211 17518-17518/? I/art: Late-enabling -Xcheck:jni
    11-10 10:26:27.427 17518-17556/rafaelmarinho.dobau D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
    11-10 10:26:27.441 17518-17518/rafaelmarinho.dobau D/Atlas: Validating map...
    11-10 10:26:27.543 17518-17518/rafaelmarinho.dobau D/AndroidRuntime: Shutting down VM
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime: FATAL EXCEPTION: main
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime: Process: rafaelmarinho.dobau, PID: 17518
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{rafaelmarinho.dobau/rafaelmarinho.dobau.Parse}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:155)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5343)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at rafaelmarinho.dobau.Parse.onCreate(Parse.java:12)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:6010)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:155) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5343) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
    11-10 10:26:27.545 17518-17518/rafaelmarinho.dobau E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
    11-10 10:26:29.382 17518-17518/rafaelmarinho.dobau I/Process: Sending signal. PID: 17518 SIG: 9

So what can I do to fix the problem?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Rafael Marinho
  • 100
  • 1
  • 10
  • `java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference` it means that you are trying to call `setDisplayHomeAsUpEnabled` on instance of `ActionBar` object, but this object is null. – Vasyl Glodan Nov 10 '15 at 13:44

1 Answers1

1

whenever your trying to disable home button or perform anything on Actionbar you should check if getSupportActionbar is not null, as this depends on the Application theme.

if(getSupportActionBar()!=null){
setDisplayShowTitleEnabled(false);
}
Nouran S. Ahmad
  • 503
  • 1
  • 5
  • 19
  • 1
    Now I realize that I have forgot to change the default code that implements some ActionBar stuff, but I'm not using ActionBar on my app. – Rafael Marinho Nov 10 '15 at 14:34