The following code generates this error message at the public void onClick
line.
Multiple markers at this line
- implements android.view.View.OnClickListener.onClick
- The method onClick(View) of type new View.OnClickListener(){} must override a superclass method
I can't understand why. This code is taken from numerous examples I've seen. What can possibly be wrong?
private Button audioButton; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); audioButton = (Button) findViewById(R.id.imageButton1); audioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View button) { if (button.isSelected()) { button.setSelected(false); } else { button.setSelected(true); } } }); }
When a method in a subclass has the same name, same parameters or signature, and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.
While it is not required to use this annotation when overriding a method, it helps to prevent errors. If a method marked with @Override fails to correctly override a method in one of its superclasses, the compiler generates an error.
When overriding a method, you might want to use the @Override annotation that instructs the compiler that you intend to override a method in the superclass. If, for some reason, the compiler detects that the method does not exist in one of the superclasses, then it will generate an error.
It depends on the type of Superclass, if it's an Abstract class you must override all your method. For concrete class, you only have to override what is required.
Check the project's properties and verify that Java Compiler -> Compiler compliance level is set to 1.6 (or a later version).
It worked for me... i am using eclipse 2021.... and ..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With