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

后端 未结 23 2511
遥遥无期
遥遥无期 2020-12-04 15:53

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 inc

相关标签:
23条回答
  • 2020-12-04 16:43

    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.

    0 讨论(0)
  • 2020-12-04 16:45

    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.

    0 讨论(0)
  • 2020-12-04 16:47

    You should clean the project , or restart Eclipse.

    0 讨论(0)
  • 2020-12-04 16:47

    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.[*]).
    0 讨论(0)
  • 2020-12-04 16:47

    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>
    
    0 讨论(0)
  • 2020-12-04 16:48

    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!

    0 讨论(0)
提交回复
热议问题