Please add the following dependency http://mvnrepository.com/artifact/org.json/json/20080701

<dependency>
   <groupId>org.json</groupId>
   <artifactId>json</artifactId>
   <version>20080701</version>
</dependency>
Answer from Raghu K Nair on Stack Overflow
🌐
GitHub
github.com › codenvy › codenvy › issues › 693
[Java] NoClassDefFoundError · Issue #693 · codenvy/codenvy
September 6, 2016 - Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject I am wondering why it is so hard to make a Maven projects work fine with external JAR libraries. I've added the needed information to pom.xml. The project wil...
Author   MPNull
Discussions

Caused by: java.lang.NoClassDefFoundError: org.json.JSONObject error
Getting below type of error from my micro service project consuming from IBM MQ while starting the server on Intellij IDEA · org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mqQueueConnectionFactory' defined in class path resource [com/aaa/bbb/ccc/co... More on experts-exchange.com
🌐 experts-exchange.com
July 25, 2023
java - org.json dependency with Maven gives NoClassDefFoundError - Stack Overflow
I am using Maven for the first time. I want to use org.json and I have added the dependency to my pom.xml: junit More on stackoverflow.com
🌐 stackoverflow.com
java - org.json.simple.jsonObject throws noclassdeffounderror proguard maven - Stack Overflow
2 Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/JSONObject - java commandline runtime error More on stackoverflow.com
🌐 stackoverflow.com
NoClassDefFoundError: org/json/JSONObject
Intellij has its own build system, it can auto sync with gradle but not the other way around, you can't use the library imported from Intellij if you want to use gradle. If you want to use Gradle build, add the dependency into build.gradle: compile group: 'org.json', name: 'json', version: '20180130' But if you want to run it from Intellij, make sure the classpath is configured correctly More on reddit.com
🌐 r/javahelp
5
2
September 27, 2017
🌐
Bukkit
bukkit.org › threads › problem-loading-libraries-with-maven-java-lang-noclassdeffounderror-org-json-jsonobject.428354
Solved - Problem loading libraries with Maven... "java.lang.NoClassDefFoundError: org/json/JSONObject" | Bukkit Forums
August 9, 2016 - Hey everybody. So I'm having a bit of trouble just using an external library, in this case, org.json (though it's the same problem for any maven...
🌐
Stack Overflow
stackoverflow.com › questions › 24988021 › org-json-simple-jsonobject-throws-noclassdeffounderror-proguard-maven
java - org.json.simple.jsonObject throws noclassdeffounderror proguard maven - Stack Overflow
... @ Kruti It may because of duplicate packages. As error triggers that android had inbuilt json library with same package name so it is conflict.If you still want to use your own built library just change the package name of your library.
🌐
Reddit
reddit.com › r/javahelp › noclassdeffounderror: org/json/jsonobject
r/javahelp on Reddit: NoClassDefFoundError: org/json/JSONObject
September 27, 2017 -

Hi all,

I am working with a JSON object and when I launch my project I get the following error:

java.lang.NoClassDefFoundError: org/json/JSONObject
     viewmodels.LaunchViewModel.buildNextLaunch(LaunchViewModel.java:64)

Looking at line 64...

JSONObject jsonObj = new JSONObject(getHTML("..."));

Looks like I have not setup the dependencies correctly. I am working with IntelliJ with Gradle and I have imported JSON into my external libraries as seen here...

https://i.imgur.com/8VqLFf9.jpg

and here...

https://i.imgur.com/MFupkXg.jpg

My question is does it need to be added to the build.gradle file? Here are my dependencies:

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
}

I think that may be the culprit? But I am still pretty new to this process so any pointers would be sweet.

Thanks!

Edit for mods: The two screenshots are of my external libraries, no code in those. I replaced the remaining screen shot with a code block. Thanks!

Top answer
1 of 2
2
Intellij has its own build system, it can auto sync with gradle but not the other way around, you can't use the library imported from Intellij if you want to use gradle. If you want to use Gradle build, add the dependency into build.gradle: compile group: 'org.json', name: 'json', version: '20180130' But if you want to run it from Intellij, make sure the classpath is configured correctly
2 of 2
1
It seems that you possibly have a screenshot of code in your post NoClassDefFoundError: org/json/JSONObject in r/javahelp . Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting. Never submit screenshots of code instead of code text! If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images. If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code. For small bits of code (less than 50 lines in total, single classes only), the default code formatter is fine (one blank line before the code, then 4 spaces before each line of code). Pastebin for programs that consist of a single class only Gist for multi-class programs, or programs that require additional files Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites. Ideone for executable code snippets that use only the console Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;) I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Find elsewhere
🌐
SpigotMC
spigotmc.org › threads › noclassdeffounderror-org-json-jsonobject.423056
Solved - NoClassDefFoundError: org/json/JSONObject | SpigotMC - High Performance Minecraft Community
March 17, 2020 - Hello guys, I am trying to program a VPN blocker but fails with the given in error: NoClassDefFoundError: org/json/JSONObject private static final...
🌐
Forge Forums
forums.minecraftforge.net › home › mod developer central › modder support › java.lang.noclassdeffounderror: org/json/jsonobject
java.lang.NoClassDefFoundError: org/json/JSONObject - Modder Support - Forge Forums
March 24, 2022 - My mod is throwing error and I tottaly don't know why. It only happens when I use mc launcher, when I started minecraft in Intellij it worked perfectly. I don't know what to do. I think it doesn't add json.jar to my mod. And I don't know how to add it correctly. It must be something with build.gr...
🌐
Google Groups
groups.google.com › g › app-inventor-open-source-dev › c › HmTNwyBi1u8
java.lang.NoClassDefFoundError for org.json.JSONObject on my local installation
Dec 07, 2017 10:00:08 AM ...idSessionException' threw an unexpected exception: java.lang.NoClassDefFoundError: org.json.JSONObject$Null is a restricted class....
🌐
Coderanch
coderanch.com › t › 658999 › java › NoClassDefFoundError-imported-json-library
NoClassDefFoundError for an imported json library (Java in General forum at Coderanch)
I am using json-simple-1.1.1.jar external library that I have added to my classpath and verified that it exists there by doing echo $CLASSPATH. When I compile my code using javac codeTest.java the program compiles with no issues . But when I try to run the program using java -classpath . codeTest I am receiveing the error : java.lang.NoClassDefFoundError: org/jason/simple/parser/ParseException.
🌐
Stack Overflow
stackoverflow.com › questions › 30952680 › noclassdeffounderror-org-json-jsonobject-hadoop-mapreduce
maven - NoClassDefFoundError: org/json/JSONObject - Hadoop MapReduce - Stack Overflow
June 20, 2015 - package com.andrew.hadoopNBA.NbaJob1; import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import org.json.*; public class PointsRankingMapper extends Mapper<Object, Text, Text, IntWritable> { public void map(Object key, Text value, Context context) throws IOException, InterruptedException { try { JSONObject jsn = new JSONObject(value.toString()); System.out.println("printing JSON " + jsn); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
🌐
GitHub
github.com › OpenRefine › OpenRefine › issues › 2917
java.lang.NoClassDefFoundError: org/json/JSONException on startup of 3.4-beta2 · Issue #2917 · OpenRefine/OpenRefine
July 10, 2020 - Extensions which have a dependency on org.json and depend on OpenRefine to include it rather than bundling it themselves will fail to initialize with the above NoClassDefFoundError. This is a general problem with dynamically loading exte...
Author   tfmorris
🌐
Experts Exchange
experts-exchange.com › questions › 27239325 › org-json-JSONException-not-found.html
Solved: org/json/JSONException not found | Experts Exchange
May 26, 2011 - import net.sf.json.JSONArray; import net.sf.json.JSONObject; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class CreateJSONArray { public CreateJSONArray(){ HashMap m1 = new HashMap(); HashMap m2 = new HashMap(); m1.put("1","a"); m1.put("2","b"); m2.put("3","c"); m2.put("4","d"); ArrayList al = new ArrayList(); al.add(m1); al.add(m2); JSONArray ja = new JSONArray(); for(int j=0; j<al.size(); j++){ HashMap m = (HashMap) al.get(j); Set s = m.keySet(); Iterator it = s.iterator(); JSONObject jo = new JSONObject(); while(it.hasNext()){ String s1 = (String)it.next(); String val = (String) m.get(s1); jo.put(s1,val); } ja.add(jo); } JSONObject jo1 = new JSONObject(); jo1.put("hashmaps", ja); System.out.println(jo1.toString()); } public static void main(String [] args){ new CreateJSONArray(); } }