A have an android project named TestAndroid. I am able to run it no problem on my android device. However I want to be able to use code from another project. So I go to my build path and add the project Test. Test is a standard java project using java6. The Test project has a class Test, which is just an empty class.
Here's where it messes up though, when I create an instance of Test in TestAndroid I get a runtime error. Here is the error I get from logcat.
05-27 21:47:49.976: E/dalvikvm(27493): Could not find class 'com.tests.eclipseisbroken.Test', referenced from method com.tests.eclipseisbroken.TestAndrodiActivity.onCreate
05-27 21:47:49.986: W/dalvikvm(27493): VFY: unable to resolve new-instance 11 (Lcom/tests/eclipseisbroken/Test;) in Lcom/tests/eclipseisbroken/TestAndrodiActivity;
05-27 21:47:49.986: D/dalvikvm(27493): VFY: replacing opcode 0x22 at 0x0008
05-27 21:47:49.986: D/dalvikvm(27493): VFY: dead code 0x000a-000d in Lcom/tests/eclipseisbroken/TestAndrodiActivity;.onCreate (Landroid/os/Bundle;)V
05-27 21:47:50.026: D/AndroidRuntime(27493): Shutting down VM
05-27 21:47:50.046: W/dalvikvm(27493): threadid=1: thread exiting with uncaught exception (group=0x40028a00)
05-27 21:47:50.056: E/AndroidRuntime(27493): FATAL EXCEPTION: main
05-27 21:47:50.056: E/AndroidRuntime(27493): java.lang.NoClassDefFoundError: com.tests.eclipseisbroken.Test
05-27 21:47:50.056: E/AndroidRuntime(27493): at com.tests.eclipseisbroken.TestAndrodiActivity.onCreate(TestAndrodiActivity.java:16)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.os.Looper.loop(Looper.java:143)
05-27 21:47:50.056: E/AndroidRuntime(27493): at android.app.ActivityThread.main(ActivityThread.java:4914)
05-27 21:47:50.056: E/AndroidRuntime(27493): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 21:47:50.056: E/AndroidRuntime(27493): at java.lang.reflect.Method.invoke(Method.java:521)
05-27 21:47:50.056: E/AndroidRuntime(27493): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-27 21:47:50.056: E/AndroidRuntime(27493): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-27 21:47:50.056: E/AndroidRuntime(27493): at dalvik.system.NativeStart.main(Native Method)
I think there must be something wrong with my eclipse install, because I had a project were I had to reference another project and it worked. I would rather fix it now that totally reinstall eclipse and all of my plugins. If anyone knows whats wrong and could help me I would greatly appreciate it. Thanks!!
Suppose you use latest Android SDK & ADT version, and you want to add a standard java project B as a dependency in android project A:
Properties -> Java Build Path -> Projects -> Add ...
Properties -> Java Build Path -> Order and Export
Now you should able to use class from the standard java library in your Android project and build/run/debug it in Eclipse.
Hope this helps.
UPDATE: The operations above just add one line into .classpath
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/projB"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With