-1

I'm making App with Android Studio.

I have a

public class MainActivity extends Activity implements View.OnClickListener, OnCheckedChangeListener

And I need to add "AppCompatActivity" to the MainActivity.

I have searched on the Internet and I found only one can be used for extends.

So I Changed to

public class MainActivity extends Activity implements View.OnClickListener, OnCheckedChangeListener, AppCompatActivity

This and AppCompatActivity has an error that "Interface expected here".

How can I solve this problem?

문경욱
  • 53
  • 2
  • 9

2 Answers2

5

The AppCompatActivity is a class not an interface so you can't use implements keyword to inherit the AppCompatActivity

You need to use extends keyword to inherit the AppCompatActivity class

Use this

public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnCheckedChangeListener

instead of

public class MainActivity extends Activity implements View.OnClickListener, OnCheckedChangeListener, AppCompatActivity
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • after i changed Activity, There is an Error. java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. I think I shouldn't change Activity – 문경욱 May 31 '19 at 08:08
  • @문경욱 for that issue please check this question https://stackoverflow.com/q/21814825/7666442 – AskNilesh May 31 '19 at 08:24
0

The 'Interface expected here' occurs when you implement a class, not an interface. AppCompatActivity is a class which you are not able to implement.

I don't know why you want to extend from Activity in addition toAppCompatActivity, AppCompatActivity inherits from Activity already.

AppCompatActivity > FragmentActivity > SupportActivity > Activity

Just write:

public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnCheckedChangeListener {

There is no need to extend Activity for you when you do it like that.

Max pm
  • 73
  • 8