Eclipse compilation error: The hierarchy of the type 'Class name' is inconsistent
Asked Answered
O

25

158

I have downloaded some open source software written in Java and tried to compile it using Eclipse. I got the error: "The hierarchy of the type 'Class name' is inconsistent" in some files. What causes these errors and how do I fix them?

Our answered 15/12, 2011 at 12:24 Comment(0)
S
181

It means you are trying to implement a non-existing interface or you're extending an non-existing class.

Try to refresh your Eclipse.

If it doesn't work, it may mean that you have a reference to a JAR that is not in the build path. Check your project's classpath and verify that the jar containing the interface or the class is in it.

Sarcastic answered 15/12, 2011 at 12:32 Comment(7)
Along the similar vain, I had a Maven dependency which was causing this error in Spring Tool Suite, the solution was to do a Maven > Download Source on the dependency in question.Ehman
Also check that the Parent is getting compiled. In my case I knew the superclass existed, but it wasnt actually getting compiled properly.Unalloyed
I had a class extending an abstract class which was implementing a missing (renamed out of eclipse) interfaceAlake
In my case I was extending a class that WAS in the class path (a jar), but it extended a third class that was in a different jar that was not in my classpath.Demonstrate
This can be caused by any incorrect implementation in the hierarchy, not only direct implementation. For exemple, A extends B, B implement C... If B is missing C import, you will have the error message in A.Atalaya
I got this error in a project where a Class was extending TestCase from JUnit 4. But JUnit 4 wasn't included in the Project. Adding JUnit 4 into the Build Path solved this problem.Deathtrap
I had a abstract class extending a class from another package. java sucksHaily
C
16

Sometimes it happens when you add a jar that YOU need, but don't include the jars that IT needs. In my case adding all the jars in tomcat/lib helped me to solve this problem. I am working on a web-app.

Chenault answered 20/2, 2013 at 14:17 Comment(1)
Thanks, this was my issue. I included GWT libs, but was missing the Java servlet API jar (servlet-api-3.1.jar from Jetty in this case).Pelting
H
13

Check your errors (tab "markers"). I had also the following error:

Archive for required library in project cannot be read...

and when that was fixed the "inconsistent-error" disappeared.

Actually I had added jars to the build path, but for some reason they could not be read with error

Archive for required library in project cannot be read or is not a valid ZIP file

So instead I added them as "External Jars". That helped and all compilation problems were no more!

Heterotaxis answered 8/2, 2012 at 7:13 Comment(0)
H
6

One more case I have had. Give the correct project path, and import it to eclipse.

Then go to Project--> Clean --> Clean all projects.

Houseless answered 21/11, 2013 at 9:55 Comment(0)
B
5

I had this problem after I upgraded the JDK to a new version. I had to update the references to libraries in Project Properties/Java Build Path.

Boundless answered 24/7, 2013 at 14:59 Comment(0)
U
5

You should clean the project , or restart Eclipse.

Unrounded answered 29/8, 2014 at 7:41 Comment(0)
C
2

You will see this error in case a some class in your library file you have in classpath has reference to non-existing classe(s) which could be in another jar file. Here, I received this error when I did not add org.springframework.beans-3.1.2.RELEASE.jar and had extended a class from org.springframework.jdbc.core.support.JdbcDaoSupport, which was in org.springframework.jdbc-3.1.2.RELEASE.jar of my classpath.

Chip answered 12/9, 2012 at 13:56 Comment(0)
P
2

The problem may be that you have included incorrect jars. I had the same problem and the reason was that I had included incorrect default JRE library in the build path of the project. I had installed Java with another version and was including JRE files of Java with a different version. (I had installed JRE 1.6 in my system and was having JRE library 1.7 included in the build path due to previously installed Java) May be you can check if the JRE library that you have included in the build path is of correct version ie. of Java version that you have installed in your system.

Pollack answered 23/4, 2013 at 6:44 Comment(0)
W
2

I 've experienced this problem on Eclipse Juno, the root cause was that although some spring jars were being included by transient maven dependencies they were included in incorrect versions.

So you should check if using a modularized framework as spring that every module (or at least the most important: core, beans, context, aop, tx, etc.) are in the same version.

To solve the problem I 've used maven dependnecy exclusions to avoid incorrect version of transient dependencies.

Whitelaw answered 19/6, 2013 at 13:13 Comment(0)
E
2

Error : the hierarchy of the type "class name" is inconsistent error.

solution : class OtherDepJar {} --> is inside "other.dep.jar" .

class DepJar extends OtherDepJar {} --> is inside "dep.jar".

class ProblematicClass extends DepJar {} --> is inside current project .

If dep.jar is in the project's classpath, but other.dep.jar isn't in the project's classpath, Eclipse will show the" The hierarchy of the type ... is inconsistent error"

Exodontist answered 12/5, 2015 at 12:32 Comment(0)
I
1

To me, the issue was due to wrong imports. In fact, one need to update the imports after adding the v7 support library.

It can be fixed by doing as follows, for each class of your project:

  1. Delete all the lines with import android.[*], in each class
  2. Reorganize your imports: from the context menu select Source/Organize Imports or (CTRL+SHIFT+O)
  3. When prompted, select the libraries android.support.[*] (and not android.[*]).
Ilailaire answered 4/7, 2014 at 15:14 Comment(0)
O
1

I was having this problem too... I found out that the hierarchy of the class that was throwing this exception, cannot be traced all way back to its root class by eclipse... I Explain:

In my case, I have 3 java project: A, B and C... where A and B are maven projects and C a regular java eclipse project...

In the project A, i have the interface "interfaceA" ... In the project B, i have the interface "interfaceB" that extends "interfaceA" In the project C, i have the concrete class "classC" that implements "interfaceB"

The "project C" was including the "project B" in its build path but not "project A" (so that was the cause of the error).... After including "project A" inside the build path of "C", everything went back to normal...

Osmund answered 5/7, 2014 at 0:55 Comment(0)
P
1

It was definitely because missing dependencies that were not in my maven pom.xml.

For example, I wanted to create integration tests for my implementation of the broadleaf ecommerce demo site.

I had included a broadleaf jar with integration tests from broadleaf commerce in order to reuse their configuration files and base testing classes. That project had other testing dependencies that I had not included and I received the "inconsistent hierarchy" error.

After copying the "test dependencies" from broadleaf/pom.xml and the associated properties variables that provided the versions for each dependency in broadleaf/pom.xml, the error went away.

The properties were:

    <geb.version>0.9.3</geb.version>
    <spock.version>0.7-groovy-2.0</spock.version>
    <selenium.version>2.42.2</selenium.version>
    <groovy.version>2.1.8</groovy.version>

The dependencies were:

<dependency>
            <groupId>org.broadleafcommerce</groupId>
            <artifactId>integration</artifactId>
            <type>jar</type>
            <classifier>tests</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.broadleafcommerce</groupId>
            <artifactId>broadleaf-framework</artifactId>
            <version>${blc.version}</version><!--$NO-MVN-MAN-VER$ -->
            <classifier>tests</classifier>
        </dependency>
        <dependency>
            <groupId>com.icegreen</groupId>
            <artifactId>greenmail</artifactId>
            <version>1.3</version>
            <type>jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>2.5.1</version>
            <type>jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymockclassextension</artifactId>
            <version>2.4</version>
            <type>jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>5.9</version>
            <type>jar</type>
            <classifier>jdk15</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>${groovy.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.gebish</groupId>
            <artifactId>geb-core</artifactId>
            <version>${geb.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.gebish</groupId>
            <artifactId>geb-spock</artifactId>
            <version>${geb.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>${spock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>${selenium.version}</version>
            <scope>test</scope>
        </dependency>
  <!-- Logging -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.12</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.6.1</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>1.6.1</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.6.1</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
                <version>2.3.1</version>
                <type>jar</type>
                <scope>test</scope>
            </dependency>
Playboy answered 20/7, 2014 at 19:37 Comment(0)
T
1

If the extended class has the issue then the above error message will gets displayed.

Example

class Example extends Example1 {

}

fix the issues in Example1

Typebar answered 28/8, 2014 at 6:39 Comment(0)
O
1

I had the same exact problem marker and solved it by removing the @Override annotation from a method that was in fact the first implementation (the "super" one being an abstract method) and not an override.

Obsolescent answered 22/9, 2014 at 12:12 Comment(0)
E
1

In my case, the import references in many of the classes contained an extra word. I solved it by editing all the files to have the correct imports. I started doing the edits manually. But when I saw the pattern, I automated it with a find..replace in eclipse. This resolved the error.

Enchantress answered 30/9, 2014 at 18:18 Comment(0)
H
0

For me it was changing the Android API level to one with Google APIs

Heeled answered 12/3, 2014 at 16:53 Comment(0)
A
0

I had a class that extends LabelProvider in a project with OSGi, there the error occured. The solution was: Adding org.eclipse.jface to the required plugins in the manifest.mf instead of importing the single packages like org.eclipse.jface.viewers

Armond answered 5/8, 2014 at 8:7 Comment(0)
G
0

if you are importing the eclipse project just 1. Go to the java build path setting under the project properties. 2. In case the JRE System library has an error sign attach to it double click it to open the Edit library window 3. Change the execution environment to the correct java version of the system or choose edit the other settings by checking the radio buttons assign to them. 4. Click finish

Gavrah answered 21/1, 2015 at 7:14 Comment(0)
C
0

When importing a GWT project in Eclipse without installing "Google Plugin for Eclipse", this will occur. After installing "Google Plugin for Eclipse", this error will disappear.

Cinderella answered 20/3, 2017 at 14:49 Comment(0)
P
0

Right click on the project folder and select "Java Build Path". Under "Java Build Path" you should be able to see libraries. Eclipse will show errors in any of those libraries. Fixing those issue will help to resolve the issue.

Pansypant answered 19/11, 2018 at 19:12 Comment(0)
L
0

I had this error after doing some git merge from a branch where my classes extended a new interface. It was enough to Refresh (F5) the File-Tree in the Package Explorer frame of Eclipse.

It seems that Eclipse did not update everything properly and so the classes were extending a non-existing-yet interface. After refresh, all errors disappeared.

Lymphocyte answered 4/2, 2019 at 14:7 Comment(0)
C
0

I had to switch from Eclipse Oxygen that I got from IBM and used IBM JDK 8 to Eclipse Photon and Oracle JDK 8. I'm working on Java customizations for .

Chinchy answered 13/9, 2019 at 16:48 Comment(0)
D
0

This error will also appear when one of the jars required by the existing dependencies is not available in current project path.

Ex:-> Current Proj depends on Lib1 depends on Lib2.

If we use one of the classes in Lib1 but Lib2 is not packaged in Lib1 or not available in current project path you'll see the issue.

Damaging answered 20/12, 2022 at 9:49 Comment(0)
A
0

I keep getting this problem with non-trivial sealed type hierarchies, where emulations of union types are sealed:

sealed interface Type1OrType2OrType3
permits Type1, Type2, Type3 {}

And then:

non-sealed interface Type1 {}
non-sealed interface Type2 {}
non-sealed interface Type3 {}

Classes that implement the non-sealed types might expose this problem. I suspect it relates to generics, too. I have reported this issue to Eclipse, which no longer reproduces, but similar issues may still do: https://bugs.eclipse.org/bugs/show_bug.cgi?id=577872

For example, the problem didn't appear in Eclipse 2023-06, but it did in 2023-09 and 2023-12.

The solution (in my case), was to remove all sealed / non-sealed types again.

Adamina answered 13/3 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.