Reputation: 1376
I'm trying to parse a JSON string in Java but I cant figure out how! I'm using lib-JSON right now:
import net.sf.json.*;
.
String jsonStr = "{'string':'JSON', 'integer': 1, 'double': 2.0, 'boolean': true}";
JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(jsonStr); // this line crashes
I get no compilation errors but when i run the program it says:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at ircbot.plugins.SiteTitle.<init>(SiteTitle.java:28)
at ircbot.Main.main(Main.java:10)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 14 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
It sounds like I'm missing some dependencies, but I don't know how to find out if or which!
Thanks in advance!
Upvotes: 1
Views: 8844
Reputation: 7748
These are the dependencies -
are you sure you added all of them in your classpath.
Upvotes: 0
Reputation: 6158
You are missing jar file. No jar file in your class path.
see this Reading JSON file error
Upvotes: 1
Reputation: 23664
I recomend grepcode Just enter the class name and you get a list of the known versions of jars
Example: here
Upvotes: 2
Reputation: 5563
Your JSON String also not valid, This the valid JSON,
{"string": "JSON","integer": "1","double": "2.0","boolean": "true" }
Upvotes: 0
Reputation: 15333
It seems you have not imported need jar file for class "org.apache.commons.lang.exception.NestableRuntimeException"
There are many classes that we use in our Java program and which don't come with Java. So we need to put Suitable Jar file for them.
Upvotes: 2
Reputation: 3025
org/apache/commons/lang -> http://commons.apache.org/lang/ Basically, use Google and get the respective jar.
Upvotes: 0