各位晚上好。
我有一个非 android 项目,其中包含我在两个不同项目中使用的一些类(一个是 Android 项目,另一个不是)。我从这个项目中导出了一个 .jar 文件以在其他项目中使用,它可以在非 android 项目中使用。在 Android 项目中,当我尝试从这个 .jar 实例化一个类时,它给了我 NoClassDefFoundError。我尝试将 .jar 放入 libs 文件夹,在 Order and Import 选项卡中对其进行检查,并将其也放入 assets 文件夹中,但这些都不起作用。有谁知道会发生什么?使用 Eclipse Kepler、Java 1.7 和 Android 4.2.2
编辑:
当我在生成错误的行中放置一个断点时,logCat 给了我:
08-15 09:32:08.970: E/dalvikvm(1051): Could not find class 'messageService.append.UserLoginAppend', referenced from method gafit.activities.LoginActivity.attemptLogin
08-15 09:32:08.970: W/dalvikvm(1051): VFY: unable to resolve new-instance 1292 (LmessageService/append/UserLoginAppend;) in Lgafit/activities/LoginActivity;
08-15 09:32:08.970: D/dalvikvm(1051): VFY: replacing opcode 0x22 at 0x0009
08-15 09:32:08.970: D/dalvikvm(1051): VFY: dead code 0x000b-002f in Lgafit/activities/LoginActivity;.attemptLogin ()V
在我从断点恢复之后:
08-15 09:35:17.660: E/AndroidRuntime(1051): FATAL EXCEPTION: main
08-15 09:35:17.660: E/AndroidRuntime(1051): java.lang.NoClassDefFoundError: messageService.Message
08-15 09:35:17.660: E/AndroidRuntime(1051): at gafit.activities.LoginActivity.onCreate(LoginActivity.java:59)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.os.Looper.loop(Looper.java:130)
08-15 09:35:17.660: E/AndroidRuntime(1051): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-15 09:35:17.660: E/AndroidRuntime(1051): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 09:35:17.660: E/AndroidRuntime(1051): at java.lang.reflect.Method.invoke(Method.java:507)
08-15 09:35:17.660: E/AndroidRuntime(1051): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
08-15 09:35:17.660: E/AndroidRuntime(1051): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
08-15 09:35:17.660: E/AndroidRuntime(1051): at dalvik.system.NativeStart.main(Native Method)
08-15 09:35:17.660: E/AndroidRuntime(1051): Caused by: java.lang.ClassNotFoundException: messageService.Message in loader dalvik.system.PathClassLoader[/data/app/gafit.activities-1.apk]
08-15 09:35:17.660: E/AndroidRuntime(1051): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-15 09:35:17.660: E/AndroidRuntime(1051): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-15 09:35:17.660: E/AndroidRuntime(1051): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-15 09:35:17.660: E/AndroidRuntime(1051): ... 14 more