The hierarchy of the type Classe is inconsistent

2020-04-06 04:05发布

I have a class that implements an abstract class. The abstract class is in another package of my project. Added the package where the class is abstract by Configure build path/Project. In class that implements is accusing the following error: The hierarchy of the type class is inconsistent

Have I to add this package somewhere else?

Thank you!

13条回答
放荡不羁爱自由
2楼-- · 2020-04-06 04:15

This means you have made an incompatible change in a super class but haven't recompiled it.

I suggest you use a build system like Maven or Ant and/or use an IDE to build all your code.

查看更多
戒情不戒烟
3楼-- · 2020-04-06 04:16

I also had this problem when tried to use some class from a plugin project in another one. I had something like myClass extends pp1Class - here i had the error, pp1Class plugin was added as a dependency. pp1Class extends pp2Class - which was a dependency in pp1 (plugin proj1) but not in my plugin. What i did was go to pp1 and where you have defined the dependency to pp2, click properties and check the "Reexport this dependency" (this is in the MANIFEST.MF). This should solve the problem, it solved mine.

查看更多
我想做一个坏孩纸
4楼-- · 2020-04-06 04:18

The hierarchy of the type A is inconsistent

The above error is mainly because of Some jars missing in the classpath eg: I was trying to implement an interface "MethodBeforeAdvice"

Here MethodBeforeAdvice implements BeforeAdvice and these two interfaces were present in one jar file called "Spring-aop-4.2.5.Release.jar"

But "BeforeAdvice" interface implements an interface "Advice" which was present in some other jar "aop-alliance-1.0.0.jar" which was not present in my class-path

查看更多
聊天终结者
5楼-- · 2020-04-06 04:19

Another reason for this error is, one of your base classes implements an interface which is in an external library, and your .classpath file is kept on a source control system (therefore readonly).

For instance, your ClassB extends ClassA and ClassA implements InterfaceA which is in LibraryA.jar. ClassA is in ProjectA, ClassB is in ProjectB. ProjectA .classpath file is readonly.

Here you have to export the LibraryA.jar from your ProjectA. But I guess due to an Eclipse bug, when a new team mate connects these projects (or occasionally when you prepare another workspace), he gets this type hierarchy error. Only way to solve this problem is to check-out .classpath file in ProjectA, remove and re-add a library (does not have to be LibraryA.jar). This operation somehow resolves the error.

查看更多
虎瘦雄心在
6楼-- · 2020-04-06 04:23

These errors happened because some interface/class in the hierarchy cannot be resolved. For example: the error is in your class - class X, X inherits Y, and in turn, Y inherits Z. However, the compiler cannot resolve z (in above error), because z is belong to a library that is not included. Therefore, you have to add package containing z to the classpath/ or project's Java Build Path (if you are using eclipse). hope it may help.

查看更多
smile是对你的礼貌
7楼-- · 2020-04-06 04:24

I actually added all the related jars and interfaces in build path but still I was facing the error so later someone suggested me to add the j2ee.jar in build path and my error just went away.

查看更多
登录 后发表回答