Java – classnotfoundexception when including library jar

In my android project, I added a library jar. Jar in the LIBS folder

>Google gson (COM. Google. Gson) > JBoss netty (org. JBoss. Netty) > my own client application, which uses these two other libraries (com.example.core)

Compile / archive jar.jar using ant

There are no errors in eclipse, but when I try to run my Android Application on the device, I get this:

E/AndroidRuntime(23807): FATAL EXCEPTION: main
E/AndroidRuntime(23807): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.project/com.example.project.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.project.MainActivity" on path: /data/app/com.example.project-1.apk
E/AndroidRuntime(23807):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
E/AndroidRuntime(23807):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime(23807):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(23807):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime(23807):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(23807):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(23807):    at android.app.ActivityThread.main(ActivityThread.java:5039)
E/AndroidRuntime(23807):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(23807):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(23807):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(23807):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(23807):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(23807): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.project.MainActivity" on path: /data/app/com.example.project-1.apk
E/AndroidRuntime(23807):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
E/AndroidRuntime(23807):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(23807):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(23807):    at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
E/AndroidRuntime(23807):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
E/AndroidRuntime(23807):    ... 11 more

It must be my jar that caused this, because if I delete the reference to its class from mainactivity, the problem will be solved and the application will run on the device

Using apktool, I checked what I entered into APK and found that everything was added to the SmalI directory, which is everything except my package (COM. Example. Core) So all the Android application classes (COM. Example. Project), gson (COM. Google. Gson) and netty (org. JBoss. Netty) in my jar are there, but not com example. core.

My environment: Eclipse 4.2 1 ADT 21.0. 1 Java 7 (Oracle)

Device I tested: Samsung Galaxy S2 LG nexus 4

Any ideas? thank you.

Solution

You will get NoClassDefFoundError because your jar file is not available at runtime

To make it available at run time, you must check the check box of the jar file in the Java build path, as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>