Reputation: 5354
I am using the ADT version 21 plugin for Eclipse, and I am programming for the Android 4.2 platform. I originally wrote a Java client-server application, and I want to use some of the classes that I wrote in it for an Android application that I am writing right now. I tried exporting the Java class files to a JAR file and putting the JAR file in the libs
directory in my Android application, but when I tried to run the application on my Nexus 4, a NoClassDefFoundError
is thrown. I searched SO for some answers and tried a few suggestions such as including the JAR file in the Order and Export tab in the Properties window (and putting it at the top of the list), but I'm stuck. Eclipse compiles my Android application fine, but I am unable to run my application on my device.
I know this question has been asked before, and several users have experienced this same issue. I welcome all suggestions. (I just started learning about Android application development.) Thanks!
EDIT: I just noticed these lines in the Console output. Any ideas?
[2012-11-24 01:26:26 - HomePage] Dx bad class file magic (cafebabe) or version (0033.0000)
...while parsing org/nihongo/common/db/Commands.class
...while processing org/nihongo/common/db/Commands.class
EDIT: I think it could be the fact that I am using Java 7 instead of Java 6. See here.
Upvotes: 0
Views: 176
Reputation: 378
NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.
This error is also generated when you make an app that uses the Google API (such as Maps) but run it on a device that targets the Android API.
Upvotes: 6
Reputation: 5354
I switched my compiler from Java 7 to Java 6 in the client-server application. I exported the class that I wanted to a JAR file, and I included it in my Android application, and it looks like it works now!
So I guess only Java 6 is supported even on Android 4.2.
Upvotes: 1