Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
            }
        }
    });
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
310 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 ..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...