1

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.access000ドル(URLClassLoader.java:58)
 at java.net.URLClassLoader1ドル.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.URLClassLoader1ドル.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!

asked Dec 2, 2011 at 9:12

6 Answers 6

2

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.

answered Dec 2, 2011 at 9:14
Sign up to request clarification or add additional context in comments.

3 Comments

But I do have the apache commons lib! But now when I look inside it there is no subpackage lang.exception... I do find org.apache.commons.lang3, but still no exceptions!
@oskob try this link, if you search then will see this jar file contains the class you are looking for. java2s.com/Code/Jar/ABC/Downloadcommonslang24jar.htm
That link looks broken :P however, it seems i used the wrong version, i tried 2.x instead of 3.x and it worked!
2

I recomend grepcode Just enter the class name and you get a list of the known versions of jars

Example: here

answered Dec 2, 2011 at 9:18

Comments

1
You are missing jar file. No jar file in your class path. 

see this Reading JSON file error

answered Dec 2, 2011 at 9:21

Comments

0

org/apache/commons/lang -> http://commons.apache.org/lang/ Basically, use Google and get the respective jar.

answered Dec 2, 2011 at 9:14

Comments

0

Your JSON String also not valid, This the valid JSON,

{"string": "JSON","integer": "1","double": "2.0","boolean": "true" }
answered Dec 2, 2011 at 9:16

Comments

0

These are the dependencies -

  1. jakarta commons-lang 2.5
  2. jakarta commons-beanutils 1.8.0
  3. jakarta commons-collections 3.2.1
  4. jakarta commons-logging 1.1.1
  5. ezmorph 1.0.6

are you sure you added all of them in your classpath.

answered Dec 2, 2011 at 9:26

2 Comments

Is there an easy way to find these dependencies? It seems like a lot of libs for just JSON parsing :S
@oskob I personally use google-gson code.google.com/p/google-gson . Apache libs are like this, lots of dependencies.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.