Search code examples
androidandroid-actionbar

Android: required android.support.v7.app.ActionBar found android.app.ActionBar


I am trying to use the getActionBar(); method and I receive this error: required android.support.v7.app.ActionBar found android.app.ActionBar . How can I correct this?


Solution

  • This error is occurring because you are creating an object and passing it to a different class reference variable. Because getActionManager gives the object of android.app.ActionBar but you are trying to assign android.app.ActionBar class object to android.support.v7.app.ActionBar.

    But both these classes provide the same functionality. android.support.v7.app.ActionBar Class is used when our uses-sdk min version is less the api 11. to get the object of ActionBar below api 11 we need android.support.v7.app.ActionBar class object.

    To get Action bar you need to follow one of two approaches.

    1. import android.support.v7.app.ActionBar and use getSupportActionBar() method od activity.

    2. go to AndroidManifest.xml file and change <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" /> and import android.app.ActionBar and use getActionBar()