开发者

JSONObject etc instantiation crashing

开发者 https://www.devze.com 2023-03-10 03:37 出处:网络
I am trying to learn how to use JSON and writing a simple program however whenever I instantiate a JSON Object it crashes.

I am trying to learn how to use JSON and writing a simple program however whenever I instantiate a JSON Object it crashes. What am I missing if I receive this error when trying to instantiate a JSONObject or JSONArray. I have added http://sourceforge.net/projects/json-lib/files/ this JSON library to the build path. Is there anything I am missing?

The error message is as follows:

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(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at jsonexp.JSONexp.<init>(JSONexp.java:36)
    at jsonexp.JSONexp.main(JSONexp.java:55)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException

I have learned that this sort of error occurs when the library being used depends on another library.

I do not know how to deal with this problem and w开发者_开发问答ould very much appreciate some help.

Thanks.


A simple way to do this would be to use findjar to find the jar containing missing class for you and add it to you lib folder.


Yes, the jar you are including has it's own runtime dependencies that are not satisfied.

java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException

When seeing these type errors, I usually google around until I find the library responsible. This particular case it is the Apache Commons Lang library. Including this jar in your class path should solve the problem


You're forgetting the jar that contains the class NestableRuntimeException.

Based on the package of that exception, it is an Apache Commons library and you must go to Apache Commons and download the Apache Commons Lang library. Download the commons-lang-x.y-bin.(tar.gz|bin) archive, get the jar from the archive and add it to your project or java classpath.

0

精彩评论

暂无评论...
验证码 换一张
取 消