oddg 类型的 onClick(View) 方法必须重写超类方法吗?
我遇到这样的错误:
“oddg 类型的 onClick(View) 方法必须重写超类 方法”。
我很困惑到底错误发生在哪里。 您能指导一下,具体错误是什么?
public class oddg extends Activity implements OnClickListener
{
ProgressDialog dialog;
int increment;
int maximum ;
private static final String TAG = "ServicesDemo";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Button startbtn = (Button) findViewById(R.id.startbtn);
startbtn.setOnClickListener(this);
}
@Override
public void onClick(View arg0)
{ }
}
这是我的代码... 提前致谢 - 昂卡
I am occurring error like:
"The method onClick(View) of type oddg must override a superclass
method".
I am confused where exactly error has occurred.
Can you please guide me, what exactly error is?
public class oddg extends Activity implements OnClickListener
{
ProgressDialog dialog;
int increment;
int maximum ;
private static final String TAG = "ServicesDemo";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Button startbtn = (Button) findViewById(R.id.startbtn);
startbtn.setOnClickListener(this);
}
@Override
public void onClick(View arg0)
{ }
}
This is my code...
Thanks in Advance--
Onkar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我认为问题在于您的编译器设置设置为 Java 1.5 而不是 Java 1.6。从 Java 1.6 开始,注释 @Override 不仅可以用于从超类继承的方法,还可以用于从接口实现的方法。但如果你的编译器仍然设置为 1.5,问题是他会检查你是否覆盖了超类的方法。在您的示例中,情况并非如此,因为您正在从接口实现方法。
作为旁注,最好在您的应用程序中遵循 Java 命名约定代码。因此所有类都以大写字母开头。
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.
我遇到了同样的问题,我像这样修复了它:
禁用
I had the same trouble and I fixed it like this:
disable
这并不直接适合这个问题,但如果您没有在类声明中声明
implements OnClickListener
,您也会收到此错误。对于更有经验的编码员来说,这可能看起来很愚蠢,但我对此很陌生,它愚弄了我。
This isn't directly appropriate to this question but you will also get this error if you haven't declared
implements OnClickListener
on the class declaration.This may seem dum to the more experienced coder but I'm new to this and it fooled me.
了解
@Override
注释。这意味着,一旦您使用@Override
注解该方法,编译器就会检查它是否确实是重写的方法,如果不是,则显示错误。此外,您必须具有语言级别 6 才能将其与接口实现方法一起使用。在 IDEA 中,您可以通过项目设置来完成此操作。
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.
我也有同样的问题。我发现解决方案写得很好导入。
我替换
为
I had the same problem. I found the solution writing well the import.
I replaced
for
“RoflcoptrException”是对的!你应该将java编译器设置为1.6
项目属性-> Java编译器->1.6
"RoflcoptrException" is right! You shoud set java compiler to 1.6
Project properties -> Java compiler ->1.6
如果您使用的是 android studio ,您还可以通过按 ctrl+O 覆盖您的方法,或者直接转到 code->;覆盖并覆盖适当的方法。
它会自动覆盖你的方法。
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 .