How to solve “The hierarchy of the type is inconsistent” error in Java Eclipse?

隐身守侯 提交于 2019-12-11 02:58:29

问题


I was trying to create an Android Application in Java Eclipse with the use of the Processing for Android but when I was about to compile it, I got this error message "The hierarchy of the type MainAcitvity is inconsistent". Here is my code:

public class MainActivity extends PApplet {

 public static void main(String args[]) 

 {

     PApplet.main(new String[] { "--present", "com.RDP.MainActivity" });

 }

 Vector path = new Vector();

 public void setup(){

     size(550,550, P3D);
     smooth();

 }

 public void draw(){
     background(255);

     LineSimplifier1 pt;
     noFill();
     strokeWeight(1);
     beginShape();

     for (int i=0; i < path.size(); i++)

     {
         pt = (LineSimplifier1)path.elementAt(i);vertex(pt.x,pt.y);

     }

     endShape();

     strokeWeight(5);

     beginShape(POINTS);

     for (int i=0; i < path.size(); i++)

     {
         pt = (LineSimplifier1)path.elementAt(i);vertex(pt.x,pt.y);      

     }

     endShape();

 }

 public void mousePressed(){

     path = new Vector();

 }

 public void mouseDragged(){

     path.add(new LineSimplifier1(mouseX, mouseY));

 }

 public void mousePressed1(){

     if (path.size() > 1)

     {
         LineSimplifier1 [] tmp = new LineSimplifier1[path.size()-1];

         for (int i =0; i < path.size()-1; i++)

         {
             tmp[i] = (LineSimplifier1)path.elementAt(i+1);

         }

         path = new Vector();
         path.addAll(Arrays.asList(AndroidRDPActivity.simplifyLine2D(5,tmp)));

     }   
 }
}

Another error is, "The type java.awt.event.MouseListener cannot be resolved. It is indirectly referenced from required .class files". Please help me solve this problem. Thanks.


回答1:


In my case, this is caused by library conflicting. In console errors print like this:

[2013-04-10 21:06:38 - miaoqu-lib] Found 3 versions of android-support-v4.jar in the dependency list,
[2013-04-10 21:06:38 - miaoqu-lib] but not all the versions are identical (check is based on SHA-1 only at this time).
[2013-04-10 21:06:38 - miaoqu-lib] All versions of the libraries must be the same at this time.
[2013-04-10 21:06:38 - miaoqu-lib] Versions found are:
[2013-04-10 21:06:38 - miaoqu-lib] Path: /home/sunshine/workspace/miaoqu-lib/libs/android-support-v4.jar
[2013-04-10 21:06:38 - miaoqu-lib]  Length: 385685
[2013-04-10 21:06:38 - miaoqu-lib]  SHA-1: 48c94ae70fa65718b382098237806a5909bb096e
[2013-04-10 21:06:38 - miaoqu-lib] Path: /home/sunshine/workspace/miaoqu-lib-actionbarsherlock/libs/android-support-v4.jar
[2013-04-10 21:06:38 - miaoqu-lib]  Length: 393154
[2013-04-10 21:06:38 - miaoqu-lib]  SHA-1: 307c1cc532eabbf1d135b43e5c983c9da700449d
[2013-04-10 21:06:38 - miaoqu-lib] Path: /home/sunshine/workspace/miaoqu-lib-slidingmenu/libs/android-support-v4.jar
[2013-04-10 21:06:38 - miaoqu-lib]  Length: 393154
[2013-04-10 21:06:38 - miaoqu-lib]  SHA-1: 307c1cc532eabbf1d135b43e5c983c9da700449d
[2013-04-10 21:06:38 - miaoqu-lib] Jar mismatch! Fix your dependencies

So I replaced the android-support-v4.jar file in lib folders of the 3 project with the same one, and problem solved. Hope this helps.




回答2:


I had this problem and solved it by:

1- Doing what is written in the Processing - Android Wiki page

"The best way to make an Android application is to use Subclipse to check out the source for processing/android/core as its own project in Eclipse. Call that project android-core. Then create a new Android project using the Eclipse ADT, and include android-core as a 'required project'."

Edit: the correct SVN path is http://processing.googlecode.com/svn/trunk/processing/core

Note: By doing this there is no need to import processing's android core.jar into your project

2- Installed JDK 7u7 and added it to eclipse, then in MyAndroidProject - Properties - Build Path - added jdk7u7 library in add library

The errors are gone but unfortunately then the app crashed in the emulator still trying to figure out why




回答3:


Your project should also reference the android-support-v4.jar (which is included in ABS's libs folder.) So, Properties->Java Build Path->Add JARs... and select that jar from ActionBarSherlock->libs




回答4:


The error says that you lack some librabries that are referenced from within the libraries you are using. Check the requirements and "How to begin" for Processing framework and others if any.

In your case, it seems that Processing needs java.awt that is the core part of Java SE but doesn't exist in Android SDK.




回答5:


Had the same problem when importing PDE Processing projects to Eclipse.

I found a work around through this link http://ghostandthemachine.github.com/blog/2011/08/03/setup/

As you ll see, he doesn't import core.jar (from processing/lib) but uses a base processing project (downloaded via svn) as library. Then edit the Activity class to extend Papplet instead of Activity etc... What i did then was copy the java code from Processing exported projects (the ones that didn't run) -and also the gifs etc from assets folder- to my new project and everything run fine (in the emulator).

One note - in the downloaded project configure build path so that the ANDROID_LIB point to your ...platforms/android-2.1/android.jar

Tomorrow i will try to locate the reason for the error (i suspect either the core.jar or the ant.properties/build.xml of the exported projects), but at the moment i lost enough sleep trying to figure this out.

Hope i helped



来源:https://stackoverflow.com/questions/8658443/how-to-solve-the-hierarchy-of-the-type-is-inconsistent-error-in-java-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!