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

263,175

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

To resolve this issue, Go to your Project properties -> Java compiler -> Select compiler compliance level to 1.6-> Apply.

Solution 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.

Maybe that helps.

Share:
263,175
Tim H
Author by

Tim H

Updated on August 30, 2020

Comments

  • Tim H
    Tim H over 3 years

    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?

    • oagostinho
      oagostinho almost 12 years
      Please check this item, it explains the use of override. I believe this practice is very important for everything not only for this situation in particularly. stackoverflow.com/questions/94361/…
  • Michael Krauklis
    Michael Krauklis over 13 years
    My project was set to 1.6, so I shot for the stars and set it to 1.5, rebuilt, then back to 1.6. Miraculously this resolved my issue. Thanks for pointing me in the right direction!
  • aditya_gaur
    aditya_gaur over 12 years
    having the same issue...tried the suggestion given in this answer but still not successful. :( :(
  • Pacerier
    Pacerier over 12 years
    @MichaelKrauklis I'm 1.6 and I'm having this issue. I've set to 1.5 and cleaned it and set back to 1.6 and cleaned it again. Still not resolved. Any ideas?
  • Wilerson
    Wilerson almost 12 years
    I did not only that, but unchecked "Start a build automatically" on the Clean dialog. Only then it worked for me.
  • NoBugs
    NoBugs almost 12 years
    Same problem here, in my case, I had not installed JDK 1.6, only the latest 1.7, which apparently doesn't work with Android. Installing the older 1.6 and then following these instructions, should work :)
  • Vasile Jureschi
    Vasile Jureschi over 11 years
    If the above solutions did not work, you can simply delete the errors in the Problems view after setting the compiler to 1.6
  • Dave Cameron
    Dave Cameron over 11 years
    I had to restart eclipse as well, even after deleting the errors.
  • gsgx
    gsgx almost 11 years
    It should be mentioned (like in the comments to the other answers) a clean build followed by a restart is often required.
  • J4cK
    J4cK over 10 years
    Just modify 1.5 to 1.6 in your YourProject->RightClick->Properties->Java Compiler->1.5, to 1.6. Apply and Yes to rebuild.
  • Jacob van Lingen
    Jacob van Lingen almost 10 years
    Many thx, thought I was going mad (project was 1.6, but just like Michael setting it to 1.5 and back did fix this problem)!
  • Matthis Kohli
    Matthis Kohli almost 9 years
    Like Anand Sunderraman said this answer combined with the next answer here is the solution.
  • uvsmtid
    uvsmtid about 8 years
    FIXED. I couldn't reliably get rid of the problem until I configured Maven (instead of Eclipse) by <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
  • phil
    phil over 7 years
    Thanks. Setting Java Version in Project->Properties->Project Facets->Java from 1.5 to 1.6 helps too, to solve this problem.
  • mljrg
    mljrg about 7 years
    I selected an "Execution Environment" then pressed OK and the error was gone. Then I came back to this same dialog, and selected "Workspace default JRE (...)", which was my previous selection when I was getting the error from Eclipse, then pressed OK, and the error did not happened ?!? This must be an Eclipse UI bug or something like that (I am on Eclipse Neon 4.6.2)
  • Asoub
    Asoub about 7 years
    Thanks, I guess this overrides parent pom configuration or something. (I ad the problem the other way around, no problem from eclipse, but maven's compiler threw me "must override etc.")