Why do I get “must override a superclass method” with @Override?

Tags: , ,

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. */
public void onCreate(Bundle savedInstanceState) {

    audioButton = (Button) findViewById(R.id.imageButton1);
    audioButton.setOnClickListener(new OnClickListener() {
        public void onClick(View button) {
            if (button.isSelected()) {
            else {


Check the project’s properties and verify that Java Compiler -> Compiler compliance level is set to 1.6 (or a later version).

Source: stackoverflow