本文翻译自:'Must Override a Superclass Method' Errors after importing a project into 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: 任何时候我必须将我的项目重新导入Eclipse(如果我重新安装Eclipse,或者更改了项目的位置), 几乎所有重写的方法都没有正确格式化,导致错误:
The method must override a superclass method 该方法必须覆盖超类方法
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. 值得注意的是,这是Android项目 - 无论出于何种原因,方法参数值并不总是填充,所以我必须自己手动填充它们。 For instance: 例如:
list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
//These arguments have their correct names
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
}
});
will be initially populated like this: 最初将填充如下:
list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
//This methods arguments were not automatically provided
public void onCreateContextMenu(ContextMenu arg1, View arg2,
ContextMenuInfo arg3) {
}
});
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. 奇怪的是,如果我删除我的代码,并让Eclipse自动重新创建方法,它使用我已经拥有的相同参数名称,所以我真的不知道问题在哪里,除此之外它自动格式化方法我。
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? 也许这是由于我格式化方法的方式,这是在另一个方法的参数内?
#1楼
参考:https://stackoom.com/question/72YU/将项目导入Eclipse后-必须覆盖超类方法-错误
#2楼
This is my second time encounter this problem. 这是我第二次遇到这个问题。 first time according the alphazero's recommendation it worked. 第一次根据alphazero的推荐它起作用了。 but in the second time I set to 1.6 it don't work it just like 'CACHE' this error after clean and rebuild. 但是在第二次我设置为1.6时它不能像'CACHE'那样在清理和重建后出现这个错误。
Try to switch off 'Build Automatically' as Rollin_s said -> error still here! 尝试关闭'自动构建',因为Rollin_s说 - >错误仍在这里!
So I removed the problem project (already set to 1.6) from Package Explorer and import it again -> it start a rebuild and no error this time 所以我从Package Explorer中删除了问题项目(已经设置为1.6)并再次导入 - >它开始重建并且这次没有错误
Hope this help someone 希望这能有所帮助
#3楼
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). Eclipse默认为Java 1.5,并且您有实现接口方法的类(在Java 1.6中可以使用@Override
进行批注,但在Java 1.5中只能应用于覆盖超类方法的方法)。
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. 转到项目/ IDE首选项并将Java编译器级别设置为1.6,并确保选择JRE 1.6以从Eclipse执行程序。
#4楼
In my case, none the solutions above works. 就我而言,上述解决方案都无效。 I have to checkout my source code to another folder. 我必须将我的源代码签出到另一个文件夹。 From eclipse select File > Switch workSpaces > Other... and then import code to the new workspaces. 从eclipse中选择File> Switch workSpaces> Other ...然后将代码导入新工作区。 it works after that. 它之后工作。
#5楼
The answer by Paul worked for me partially. 保罗的答案部分地为我工作。 I still had one error then. 那时我还有一个错误。 So, in addition to that, I also had to go to Properties-> Project Facets and there set the Java version from 1.5 to 1.6. 因此,除此之外,我还必须转到Properties-> Project Facets,并将Java版本设置为1.5到1.6。
Maybe that helps. 也许这有帮助。
#6楼
Fixing must override a super class method error is not difficult, You just need to change Java source version to 1.6 because from Java 1.6 @Override annotation can be used along with interface method. 修复必须覆盖超类方法错误并不困难,您只需要将Java源版本更改为1.6,因为从Java 1.6 @Override注释可以与接口方法一起使用。 In order to change source version to 1.6 follow below steps : 要将源版本更改为1.6,请按照以下步骤操作:
- Select Project , Right click , Properties 选择Project,右键单击Properties
- Select Java Compiler and check the check box "Enable project specific settings" 选择Java Compiler并选中“启用项目特定设置”复选框
- Now make Compiler compliance level to 1.6 现在使编译器合规性级别达到1.6
- Apply changes 应用更改