Reputation: 21
I am new to Android and tried to run the sample code of the SDK using eclipse. I created the project (via File → New → Project → Android → Android Sample Project), but when I run the project it shows the following error for all the sample projects:
Multiple markers at this line
- The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
- implements android.view.View.OnClickListener.onClick
Then I refered to this forum. Here they mentioned a "compiler compliance level". But my compiler compliance level is on 1.7, and I am using Android 4.0.3 with an API level of 15.
So please help me to rectify this error.
Upvotes: 0
Views: 2117
Reputation: 2653
I just had the same issue.I fixed it by following change of code
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Use View.OnClickListener(){} instead of just OnClickListener(){};
I think this might due to various OnClickListener are there. May be we need to specify which is the relevant one. I would really love to know the real reason if any one knows.
Upvotes: 0
Reputation: 213
Make sure that above your OnClick method you have the annotation @Override like so
@Override
public void OnClick(View v) {
//Code goes here
}
By having @Override, Java knows that you are not creating a new method, in this situation you are letting Java know that you are utilizing that listener.
If you have already done this, check this website http://androidcodemonkey.blogspot.com/2011/10/how-to-solve-must-override-superclass.html
Upvotes: 1
Reputation: 13101
Remove the @Override annotation tag.
For some situation. the eclipse can't recognize.
Upvotes: 0