将项目导入 Eclipse 后出现“必须覆盖超类方法"错误 [英] 'Must Override a Superclass Method' Errors after importing a project into Eclipse

查看:32
本文介绍了将项目导入 Eclipse 后出现“必须覆盖超类方法"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何时候我必须将我的项目重新导入到 Eclipse 中(如果我重新安装 Eclipse,或者更改了项目的位置),几乎所有我覆盖的方法都没有正确格式化,从而导致错误:

Anytime I have to re-import my projects into Eclipse (if I reinstalled Eclipse, or changed the location of the projects), almost all of my overridden methods are not formatted correctly, causing the error:

该方法必须覆盖超类方法

The method must override a superclass method

值得一提的是,无论出于何种原因,这都是 Android 项目,方法参数值并不总是填充,所以我必须自己手动填充它们.例如:

It may be noteworthy to mention this is with Android projects for whatever reason, the method argument values are not always populated, so I have to manually populate them myself. For instance:

list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

    //These arguments have their correct names
    public void onCreateContextMenu(ContextMenu menu, View v, 
                                    ContextMenuInfo menuInfo) {                 
    }

});

最初会像这样填充:

list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

    //This methods arguments were not automatically provided    
    public void onCreateContextMenu(ContextMenu arg1, View arg2,
                                    ContextMenuInfo arg3) {
    }

});

奇怪的是,如果我删除我的代码,并让 Eclipse 自动重新创建该方法,它会使用我已经拥有的相同参数名称,所以我真的不知道问题出在哪里,否则它会自动格式化适合我的方法.

The odd thing is, if I remove my code, and have Eclipse automatically recreate the method, it uses the same argument names I already had, so I don't really know where the problem is, other then it auto-formatting the method for me.

不得不手动重新创建我所有被覆盖的方法,这变得非常痛苦.如果有人可以解释为什么会发生这种情况或如何解决它.我会很高兴.

This becomes quite a pain having to manually recreate ALL my overridden methods by hand. If anyone can explain why this happens or how to fix it. I would be very happy.

也许是因为我格式化方法的方式,这些方法在另一个方法的参数中?

Maybe it is due to the way I am formatting the methods, which are inside an argument of another method?

推荐答案

Eclipse 默认为 Java 1.5 并且您有实现接口方法的类(在 Java 1.6 中可以用 @Override 注释,但是在 Java 1.5 中只能应用于覆盖超类方法的方法).

Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 can be annotated with @Override, but in Java 1.5 can only be applied to methods overriding a superclass method).

转到您的项目/IDE 首选项并将 Java 编译器级别设置为 1.6,并确保您选择 JRE 1.6 以从 Eclipse 执行您的程序.

Go to your project/IDE preferences and set the Java compiler level to 1.6 and also make sure you select JRE 1.6 to execute your program from Eclipse.

这篇关于将项目导入 Eclipse 后出现“必须覆盖超类方法"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆