How to resolve the Android error "method setSupportActionBar in class AppCompatActivity cannot be applied to given types"?
Solution 1
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
..... />
Solution 2
I have problem same with you
I change extends Activity
to extends ActionBarActivity
Like this:
public class myclass extends Activity
to
public class myclass extends ActionBarActivity
Solution 3
Change android.widget.Toolbar
import statement to android.support.v7.widget.Toolbar
import android.support.v7.widget.Toolbar;
Swarathesh Addanki
Updated on July 16, 2022Comments
-
Swarathesh Addanki almost 2 years
I'm making an Android app using
appcompat
usingcom.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
-
Rushabh Gedam almost 4 yearslong time no replies, Is that helpful or not ?