Java – NoClassDefFoundError occurs when referencing from an Android project to a standard Java project

NoClassDefFoundError occurs when referencing from an Android project to a standard Java project… here is a solution to the problem.

NoClassDefFoundError occurs when referencing from an Android project to a standard Java project

I’m currently working on an android app that needs to use some shared classes that are also used on some server side.
So, on the one hand, I have this standard java project in eclipse with some POJOs, infercaes, and so on. On the other hand, I have an android app project with an activity that should use these POJOs.

My first attempt to let the Android project know that the Java project just added it as a “required project” to the build path property in Eclipse. The result is:

java.lang.NoClassDefFoundError: my.package.Pojo

I googled and tried a lot, but the problem still exists :

How do I set everything up correctly so that my ADT v21.1 android project recognizes my java project even at runtime?

Something I’ve tried but nothing seems to have changed :

  • After adding the Required Items, I also set the dependencies to export under the Eclipse Order and Export dialog

  • I tried building the java project as a jar file and adding it as a jar dependency to the android project

  • I created an Android library project as “

  • glue”: I added the Java project as a dependency to the library project and the library project as an “Android dependency” to the Android project

  • I checked all items within the same parent folder Chinese piece system (read, otherwise the underlying ant tasks might have some trouble).

  • I googled for a long time

It would be great if someone could help. Maybe I just missed something small?

Brudy

Solution

The problem is that I build a java project with Java 7 and Android doesn’t seem to support it. “Phix” pointed this out in his very helpful post (which he also introduced in self):
https://stackoverflow.com/a/13304441/1145459

(Bluddymarri’s answer, I just posted it here to help him close it.)

Related Problems and Solutions