按钮的 OnClick 处理程序无法决定是否要覆盖或要覆盖什么
我可以编译以下内容(通过注释掉“@Override”):
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new OnClickListener() {
//@Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this, Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
...但这会导致我的应用程序崩溃。当我注释掉时,它运行良好(但我没有按钮处理程序)。
该类应该有一个“implements OnClickListener”吗?看起来我应该这样做,但它可以在没有它的情况下进行编译,并且不会使用它进行编译(无论我是否注释掉“覆盖”,它都是不高兴的)。
I can get the following to compile (by commenting out the "@Override"):
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new OnClickListener() {
//@Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this, Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
...but it causes my app to crash. When I comment out it runs fine (but I have no button handler).
Should the class have a "implements OnClickListener"? It seems like I should, but it compiles without it, and won't compile WITH it (whether I comment out the "override" or not, it's unhappy).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我的建议,删除
@Override
行并不好。你需要在你的eclipse中更改JDK版本,这样你就不会出现这样的错误。按照以下步骤操作,右键单击您的项目并单击它。选择属性。
然后从左侧部分选择 Java Compiler &选择您安装的 JDK 版本。如果已选择,则取消选择并取消选择。尝试一下。
as per my suggestion, it is not good to remove
@Override
line. you need to change to JDK version in your eclipse then you will not get such errors. Follow, following steps for it,Right Click on your Project & select Properties.
Then from the left section Select Java Compiler & select the Version of the JDK you installed. If it is already selected then de-select it & try it.
不要删除@Override。只需在类声明行中替换
为
setOnClickListener(new View.OnClickListener() {
)并将
implements OnClickListener
替换为implements View.OnClickListener
即可。然后编译你的问题就解决了。
Dont remove @Override. just replace
with
setOnClickListener(new View.OnClickListener() {
and also replace
implements OnClickListener
withimplements View.OnClickListener
in your class declaration line.save and then compile . your problem will get solved.