Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject

I'm using org.json.JSONObject to pass the parameters to the server. And I'm using Eclipse IDE. I have already added the java-json.jar file to the build path of the project. but still I'm getting the below exception while running the code and no compilation error is displayed. I did clean the project and refreshed several times but still I end up with exception. is there anything missing?

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
like image 718
Nani Avatar asked Mar 24 '15 06:03

Nani


3 Answers

Download the Json jar from here and add it to the classpath. If its a web application then add its under lib's.

like image 93
Anand Kadhi Avatar answered Nov 13 '22 16:11

Anand Kadhi


I have added the same java-json.jar file to the Run configuration's class path of the particular java file. And now it's working absolutely fine. thanks everyone!!!

like image 33
Nani Avatar answered Nov 13 '22 14:11

Nani


Add maven dependency in pom.xml

<dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
    </dependency>
like image 2
iqbal lone Avatar answered Nov 13 '22 15:11

iqbal lone