Solve the Eclipse add external jars to run a Java. Lang. NoClassDefFoundError method

  • 2020-04-01 01:52:42
  • OfStack

Recently discovered a problem, sometimes to an Android project and Add the jar and remove the jar, found the compiler can pass, but to run when applied to the object of the external jar, throws Java. Lang. NoClassDefFoundError exception. Causes the program to crash.

Looking at the project properties, I found that Android Dependencies were missing from the normal project in the Java build path:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201305/201305100939384.png ">

By comparing it to the project before it was lost, the difference was found in the.classpath file at the root of the project. Classpathentry exported = "true" kind = "con" path = ". Com. Android. Ide eclipse. Adt. LIBRARIES "/ > Here the exported becomes false, so change this back to true, and then close and open the project again, and the result is ok.

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201305/201305100939385.png ">


In addition, if the jar you imported is not placed in the \libs directory of the project directory, this will also be a problem. Please put the jar into the \libs directory, otherwise it will compile well, but the jar is not packed in when it is packaged, which will cause the above exception. Eclipse will automatically package the files in the \libs directory when compiling.

This issue has not come up much before, and I wonder if it is related to the Eclipse version and the ADT version.


Related articles: