按钮的 OnClick 处理程序无法决定是否要覆盖或要覆盖什么

发布于 2024-12-29 09:36:38 字数 600 浏览 4 评论 0原文

我可以编译以下内容(通过注释掉“@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除会话 2025-01-05 09:36:38

根据我的建议,删除 @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.

街道布景 2025-01-05 09:36:38

不要删除@Override。只需在类声明行中替换

setOnClickListener(new OnClickListener() {

setOnClickListener(new View.OnClickListener() {)

并将 implements OnClickListener 替换为 implements View.OnClickListener 即可

。然后编译你的问题就解决了。

Dont remove @Override. just replace

setOnClickListener(new OnClickListener() {

with setOnClickListener(new View.OnClickListener() {

and also replace implements OnClickListener with implements View.OnClickListener in your class declaration line.

save and then compile . your problem will get solved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文