1

Hi i have made a simple food ordering app , but When I start it , it crashes and the error thrown in Logcat is this.Please Help Me out...

 05-18 17:26:41.104 18166-18166/com.example.sample E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.example.sample, PID: 18166

 java.lang.RuntimeException: Unable to start activity > 

ComponentInfo{com.example.sample/com.example.sample.MainActivity}: java.lang.NullPointerException: > 

Attempt to invoke virtual method 'void androidx.appcompat.app.ActionBar.hide()' on a null object

reference

   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2487)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2547)
   at android.app.ActivityThread.access$1100(ActivityThread.java:151)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:157)
   at android.app.ActivityThread.main(ActivityThread.java:5603)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void > > > 


androidx.appcompat.app.ActionBar.hide()' on a null object reference
     at com.example.sample.MainActivity.onCreate(MainActivity.java:39)
     at android.app.Activity.performCreate(Activity.java:6355)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2440)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2547) 
   at android.app.ActivityThread.access$1100(ActivityThread.java:151) 
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398) 
   at android.os.Handler.dispatchMessage(Handler.java:102) 
   at android.os.Looper.loop(Looper.java:157) 
   at android.app.ActivityThread.main(ActivityThread.java:5603) 
   at java.lang.reflect.Method.invoke(Native Method) 
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) 
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) 

Entire code - Github.

Hope You Have All Required Files , ask me if not there. Please Help!!!!

1
  • Always mention Your error module that where you are getting null pointer exception Commented May 18, 2020 at 13:13

1 Answer 1

1

In your MainActivity you use getSupportActionBar().hide(); but in your style.xml showing you set no actionbar.

   <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Either Add toolbar in your activity or add DarkActionBar instead of NoActionBar

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.