Home 'Must Override a Superclass Method' Errors after importing a project into Eclipse

# 'Must Override a Superclass Method' Errors after importing a project into Eclipse

Tim H
1#
Tim H Published in 2009-11-05 03:17:53Z
 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. 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) { } });  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. 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?
Lii
2#
 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). 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.
Paul
3#
 With Eclipse Galileo you go to Eclipse -> Preferences menu item, then select Java and Compiler in the dialog. Now it still may show compiler compliance level at 1.6, yet you still see this problem. So now select the link "Configure Project Specific Settings..." and in there you'll see the project is set to 1.5, now change this to 1.6. You'll need to do this for all affected projects. This byzantine menu / dialog interface is typical of Eclipse's poor UI design.
Eagle
4#
 In case this happens to anyone else who tried both alphazero and Paul's method and still didn't work. For me, eclipse somehow 'cached' the compile errors even after doing a Project > Clean... I had to uncheck Project > Build Automatically, then do a Project > Clean, and then build again. Also, when in doubt, try restarting Eclipse. This can fix a lot of awkward, unexplainable errors.
Sathya
5#
 To resolve this issue, Go to your Project properties -> Java compiler -> Select compiler compliance level to 1.6-> Apply.
will824
6#
 Guys in my case none of the solutions above worked. I had to delete the files within the Project workspace: .project .classpath And the folder: .settings Then I copied the ones from a similar project that was working before. This managed to fix my broken project. Of course do not use this method before trying the previous alternatives!.
ob.yann
7#
 This is my second time encounter this problem. first time according the alphazero's recommendation it worked. but in the second time I set to 1.6 it don't work it just like 'CACHE' this error after clean and rebuild. Try to switch off 'Build Automatically' as Rollin_s said -> error still here! 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 Hope this help someone
Hắc Huyền Minh
8#
Hắc Huyền Minh Reply to 2013-06-16 04:32:40Z
 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. it works after that.
tareq
9#
 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. Maybe that helps.
10#
 Go to windows-> preferences -> Java -> compiler -> Select compiler compliance level to 1.6(which version you want)-> Apply-> ok. now its work.
Sunil
11#
 If nothing of the above helps, make sure you have a proper "Execution environment" selected, and not an "Alternate JRE". To be found under: Project -> Build Path -> Libraries Select the JRE System Library and click Edit.... If "Alternate JRE ..." is selected, change it to a fitting "Execution Environment" like JavaSE-1.8 (jre1.8.0_60). No idea why, but this will solve it.
 In my case this problem happened when I imported a Maven project into Eclipse. To solve this, I added the following in pom.xml:  ... 1.8 1.8  Then in the context menu of the project, go to "Maven -> Update Project ...", and press OK. That's it. Hope this helps.