Search code examples
androidandroid-support-libraryandroid-appcompatandroid-toolbarandroid-actionbar-compat

How to resolve the Android error "method setSupportActionBar in class AppCompatActivity cannot be applied to given types"?


I'm making an Android app using appcompat using com.android.support:appcompat-v7:23.0.3 and getting following error.

Error:(22, 9) error: method setSupportActionBar in class AppCompatActivity cannot be applied to given types; required: android.support.v7.widget.Toolbar found: android.widget.Toolbar reason: actual argument android.widget.Toolbar cannot be converted to android.support.v7.widget.Toolbar by method invocation conversion


Solution

  • First of all appcompat 23.0.3 doesn't exist.

    Use 23.0.1

    com.android.support:appcompat-v7:23.0.1
    

    Then the method setSupportActionBar works with android.support.v7.widget.Toolbar.

    Check the import in your code.
    When you are using the Toolbar,you have to use the right import:

    import android.support.v7.widget.Toolbar;
    

    Finally also in your layout, you have to use the right widget.

    <android.support.v7.widget.Toolbar
        ..... />