Android Error [Attempt to invoke virtual method 'void android.app.ActionBar' on a null object reference]

后端 未结 24 2021
误落风尘
误落风尘 2020-11-28 22:13

I have a code module which implements viewpager with navigation drawer, however, when I run the code I get the following error

01-26 09:20:02.958: D/AndroidR         


        
24条回答
  •  天命终不由人
    2020-11-28 22:38

    I am a new to Android App development. I faced this error and spend almost 5 hours trying to fix it. Finally, i found out the following was the root cause for this issue and if anyone to face this issue again in the future, please give this a read.

    I was trying to create a Home Activitiy with a Video Background, for which i had to change the parent theme from the default setting of Theme.AppCompat.Light.DarkActionBar to Theme.AppCompat.Light.NoActionBar. This worked fine for the Home Activity, but when i set a new button with a onclicklistener to navigate to another Activity, where i had set a custom text to the Action Bar, this error is thrown.

    So, what i ended up doing was to create two themes and assigned them to the activities as follows.

    Theme.AppCompat.Light.DarkActionBar - for Activities with Action Bar (default)
    Theme.AppCompat.Light.NoActionBar - for Activities without Action Bar 
    

    I have made the following changes to make fix the error.

    1. Defining the themes in styles.xml

      
      
      
      
    2. Associating the Activities to their Respective Themes in AndroidManifest.xml

      
      
      
      

提交回复
热议问题