PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, June 25, 2022

[FIXED] Why do I get "must override a superclass method" with @Override?

 June 25, 2022     android, compiler-errors, java     No comments   

Issue

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);
            }
        }
    });
}

Solution

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



Answered By - Diego Torres Milano
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing