I am trying to generate a jar file for a java project and then references the jar file in an android project. As a test, I create a simple java project only containing the following class
package test;
public class Test {
public static void hello(){
System.out.println();
}
public static void main(String[] args){
hello();
}
}
I export this project an executable Jar file under Eclipse. Then I copy this jar file into the "libs" folder of an android project, so the jar file occurs in the private library and I check the box of private libary under the "Order and Export" tab. I reference the jar file by adding the following statement into the onCreate() of the main activity of the android project
Test.hello(); //reference the jar file
However, when I run the Android project, I get the
java.lang.NoClassDefFoundError: test.Test
error. The full error track trace is below
10-17 23:14:52.976: E/AndroidRuntime(16725): FATAL EXCEPTION: main
10-17 23:14:52.976: E/AndroidRuntime(16725): java.lang.NoClassDefFoundError: test.Test
10-17 23:14:52.976: E/AndroidRuntime(16725): at
com.skyhookwireless.samples.wpsapitest.WpsApiTest.onCreate(WpsApiTest.java:71)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.Activity.performCreate(Activity.java:4470)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.ActivityThread.access$600(ActivityThread.java:128)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.os.Handler.dispatchMessage(Handler.java:99)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.os.Looper.loop(Looper.java:137)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
android.app.ActivityThread.main(ActivityThread.java:4517)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
java.lang.reflect.Method.invokeNative(Native Method)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
java.lang.reflect.Method.invoke(Method.java:511)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-17 23:14:52.976: E/AndroidRuntime(16725): at
dalvik.system.NativeStart.main(Native Method)
Attached are the screenshots of the order and export tab and the jars contained in each library.
Does anyone know how I can correct this?
I've read couple of posts (e.g. this) on this site regarding the NoClassDefFoundError and tried the solutions listed in comments or answers. But no one solves my problem in this simple scenario.