Reading JSON file error
I try to read JSON file with Java. The code is:
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream("j.txt");
String jsonTxt = IOUtils.toString( is );
JSONObject json = (JSONObject) JSONSerializer.toJSON( jsonTxt );
JSONObject routes = json.getJSONObject("routes");
JSONObject legs = routes.getJSONObject("legs");
JSONObject distance = legs.getJSONObject("distance");
String dist = distance.getString("text");
}
And the line JSONObject json = (JSONObject) JSONSerializer.toJSON( jsonTxt );
makes an error:
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:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at antmedic.algorith开发者_运维知识库m.SimpleParser.main(SimpleParser.java:24)
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 13 more
Java Result: 1
I would be grateful for solving this problem.
Latest version of Commons Lang (currently 3.1) has package name of org.apache.commons.lang3
instead of org.apache.commons.lang
. For the later package name (as in your case), you should download 2.6 version of Commons Lang.
Sounds like you don't have apache commons jar file in you class path
You are missing some jar dependency which contains org.apache.commons.lang.exception.NestableRuntimeExceptio class. Look on internet where to find this class and add this jar in your classpath (in this case Apache Common Lang)
You can update your maven pom.xml file with this. I had to specify 2.3 for the version to get it to download.
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
精彩评论