I’m very new to android and I get this error when I try to run my android project.
java.lang.NoClassDefFoundError: org.json.simple.JSONValue
E/AndroidRuntime( 502): at in.juspay.PaymentService.initOrder(PaymentService.java:165)
E/AndroidRuntime( 502): at com.example.HelloMobile.LoginActivity$1.onClick(LoginActivity.java:124)
E/AndroidRuntime( 502): at android.view.View.performClick(View.java:2485)
E/AndroidRuntime( 502): at android.view.View$PerformClick.run(View.java:9080)
E/AndroidRuntime( 502): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 502): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 502): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 502): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 502): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 502): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 502): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 502): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 502): at dalvik.system.NativeStart.main(Native Method)
I have jar file which is written by me and built using maven tool. When I do :
mvn clean install
there where no error and everything works file but when I add the jar to my android project and try to run I’m getting this error.
Here are my maven dependencies from pom.xml file:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
Not sure why the error occurs.
Thanks for your help.
The jar you got after “mvn clean install” only contains the class from your project. Classes from those dependency jar are not included, so you got a NoClassDefFoundError exception.
If you really need to build a fat jar, which include all the dependencies, I will suggest maven-assembly-plugin. Following is a working example(put it in your pom.xml):
After you get the jar(in target directory), you can run “jar -tf theJarFile” to check whether the class is included.