The method onClick(View) of type oddg must override a superclass method?

后端 未结 7 1607
逝去的感伤
逝去的感伤 2021-02-19 04:23

I am occurring error like:

\"The method onClick(View) of type oddg must override a superclass method\".

I am confused where exact

相关标签:
7条回答
  • 2021-02-19 04:59

    I think the problem is that you're compiler settings are set to Java 1.5 instead of Java 1.6. Since Java 1.6 the annotation @Override is not only possible for inherited methods from a superclass but also for implemented methods from an interface. But if your compiler is still set to 1.5 the problem is that he will check if you're overwriting a method from a super class. In your example this is not the case since you're implementing a method from an interface.

    As a side note it would be good to follow Java Naming Conventions in your code. So all classes begin with an upper case letter.

    0 讨论(0)
  • 2021-02-19 05:01

    Read about @Override annotation. It means, that once you have annotated the method with @Override, the compiler checks if it really an overrided method, and shows an error if its not.

    Also, you have to have Language Level 6 in order to use it with interface implementing methods. In IDEA you can do it via Project Setup.

    0 讨论(0)
  • 2021-02-19 05:03

    I had the same trouble and I fixed it like this:

    • Open Project settings->Java Compiler
    • Set Enable Project Specific Settings to disable
    0 讨论(0)
  • 2021-02-19 05:08

    If you are using android studio , you can also override your method by pressing ctrl+O or just go to code-> Overide and override appropriate method . It will automatically override your method .

    0 讨论(0)
  • 2021-02-19 05:09

    I had the same problem. I found the solution writing well the import.

    I replaced

    import android.content.DialogInterface.OnClickListener; //(wrong)
    

    for

    import android.view.View.OnClickListener;
    
    0 讨论(0)
  • 2021-02-19 05:14

    "RoflcoptrException" is right! You shoud set java compiler to 1.6 Project properties -> Java compiler ->1.6

    0 讨论(0)
提交回复
热议问题