@Override Error in Eclipse: How to Defeat "Must Override a Superclass Method"

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Introduction: Why is Eclipse Yelling at You?

\n\n

You imported a foreign project into Eclipse, clicked Build, and suddenly — dozens of red crosses. The error: "Must Override a Superclass Method". Sound familiar? If you are learning to program in Java or working with someone else's code, this situation is a real bummer. Especially when the project built perfectly in another IDE or via Maven.

\n\n

On Stack Overflow, this question has garnered thousands of views. And for good reason: the problem is insidious. Eclipse is a powerful environment, but its compiler settings can play a nasty trick. In this article, we will break down where the "Must Override a Superclass Method" error comes from, and most importantly — how to fix it once and for all.

\n\n

We will look at three main causes and provide step-by-step instructions with real code examples. You will learn how to configure Eclipse so it doesn't complain about correct code, and how to avoid this problem in the future.

\n\n

What Does the "Must Override a Superclass Method" Error Mean?

\n\n

The error occurs when you use the @Override annotation before a method that, according to Eclipse, does not override a method from a parent class or interface. In reality, the problem is most often not in your code, but in the Java compiler settings in Eclipse.

\n\n

The @Override annotation was introduced in Java 5 (1.5) for methods overriding superclass methods. But in Java 6, it was allowed to be used for methods implementing interfaces as well. If your project is set to Java 5, but you are writing code for Java 8 — Eclipse will complain.

\n\n

Here is a typical example that causes the error:

\n\n
public interface Animal {\n    void makeSound();\n}\n\npublic class Dog implements Animal {\n    @Override\n    public void makeSound() {\n        System.out.println("Woof!");\n    }\n}\n
\n\n

If the project's compliance level is Java 5, Eclipse will say: "Must Override a Superclass Method". Even though the code is perfectly correct for Java 6 and above.

\n\n

Cause 1: Incorrect Compiler Compliance Level

\n\n

This is the most common cause. Eclipse has a setting called Compiler compliance level, which determines which version of Java it expects. If you import a project created in another IDE, this setting often gets reset to an outdated version.

\n\n

How to Fix:

\n
    \n
  1. Right-click on the project → Properties.
  2. \n
  3. Go to Java Compiler.
  4. \n
  5. Uncheck "Use compliance from execution environment".
  6. \n
  7. Select a Compiler compliance level — for example, 1.8 or 11 (depending on your project).
  8. \n
  9. Click Apply and Close.
  10. \n
  11. Rebuild the project: Project → Clean.
  12. \n
\n\n

Important: If you have multiple JDKs installed, make sure the correct version is specified in Installed JREs (Window → Preferences → Java → Installed JREs). Otherwise, Eclipse may not find the required compiler.

\n\n

Cause 2: JRE System Library Does Not Match the Compliance Level

\n\n

Sometimes the project has an old version of the JRE System Library (e.g., J2SE-1.4) specified, while your code uses annotations from Java 5+. Eclipse sees this mismatch and generates an error.

\n\n

How to Fix:

\n
    \n
  1. Right-click on the project → Build Path → Configure Build Path.
  2. \n
  3. Go to the Libraries tab.
  4. \n
  5. Find JRE System Library.
  6. \n
  7. Remove it (the Remove button).
  8. \n
  9. Click Add Library → JRE System Library → Next.
  10. \n
  11. Select Workspace default JRE (or the required JDK version).
  12. \n
  13. Click Finish and then Apply and Close.
  14. \n
  15. Clean the project: Project → Clean.
  16. \n
\n\n

Cause 3: Project Facets and Java Version Mismatch

\n\n

In Eclipse, Project Facets (used for web applications, Maven, etc.) can also set a Java version. If the facet version is lower than what your code requires, the error will appear.

\n\n

How to Fix:

\n
    \n
  1. Right-click on the project → Properties.
  2. \n
  3. Go to Project Facets.
  4. \n
  5. Find Java in the list.
  6. \n
  7. Select the required version (e.g., 1.8 or 11).
  8. \n
  9. Click Apply and Close.
  10. \n
\n\n

Note: If the project uses Maven, you can also specify the version in the pom.xml file:

\n\n
<properties>\n    <maven.compiler.source>1.8</maven.compiler.source>\n    <maven.compiler.target>1.8</maven.compiler.target>\n</properties>\n
\n\n

After that, update the project: right-click → Maven → Update Project.

\n\n

What to Do If Nothing Helps?

\n\n

If you have tried all the methods, but the error persists, try the following:

\n\n
    \n
  1. Delete the .metadata folder in the workspace (but be careful — this will reset all Eclipse settings).
  2. \n
  3. Create a new workspace and import the project again.
  4. \n
  5. Check the code: maybe you really are not overriding a method (e.g., a typo in the method signature).
  6. \n
  7. Use a different IDE: IntelliJ IDEA or NetBeans handle such situations more flexibly.
  8. \n
\n\n

Conclusion

\n\n

The "Must Override a Superclass Method" error in Eclipse is most often caused by incorrect compiler settings, not by your code. By changing the Compiler compliance level or the JRE System Library, you can fix the problem in a couple of minutes.

\n\n

Remember: if the code compiles successfully in another environment (Maven, IntelliJ IDEA), the issue is definitely in Eclipse. Don't rush to rewrite the code — just configure the environment correctly.

\n\n

We hope this guide helped you. If you have questions or your own solutions, share them in the comments!

Blogs

Book Recommendations