我的jdk版本是1.4.2
别人给了我个json-lib-2.2.1-jdk15.jar。
- Java code
import java.util.List;import net.sf.json.JSONArray;import net.sf.json.JSONObject;public class JsonDemo { public JsonDemo(){} public static String formToJson(Object o){ JSONObject jo=JSONObject.fromObject(o); return jo.toString(); } public static String listToJson(List l){ JSONArray jo=JSONArray.fromObject(l); return jo.toString(); } public static void main(String[] args){ String str[]={"aaa","bbb","ccc"}; System.out.println("formToJson="+formToJson(str)); }}
我运行个程序出现下面异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
at JsonDemo.formToJson(JsonDemo.java:14)
at JsonDemo.main(JsonDemo.java:25)
------解决方案--------------------