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

后端 未结 24 2028
误落风尘
误落风尘 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 23:04

    Whenever such an error occurs. Try to check Following Things

    1. Check what kind of Activity is being used, is it a simple android.app Activity or an AppCompatActivity or an ActionBarActivity and so on.

    2. Check if your activity type which is extended falls under the compat category

    example android.app based Activity/Fragment are non appCompat types, whereas android.support.v4.app.Fragment or android.support.v4.app.ActivityCompat are appCompat based

    if it falls under appCompat we use getSupportActionBar() else for android.app types we can use getActionBar()

    1. Check the theme applied to the activity in question in the manifest file

    example: In the manifest file if theme applied is say android:theme="@android:style/Theme.Holo.Dialog" getActionBar() will work

    but if theme applied for the activity in the manifest is as follows android:theme="@style/Theme.AppCompat.Light" then you have to use getSupportActionBar()

提交回复
热议问题