1. Error description
Exception in thread "main" Java.lang.noclassdeffounderror:org/apache/commons/collections/map/listorderedmapat Net.sf.json.jsonobject.<init> (jsonobject.java:1450) at Net.sf.json.util.cycledetectionstrategy.<clinit > (cycledetectionstrategy.java:37) at net.sf.json.jsonconfig.<clinit> (jsonconfig.java:65) at Net.sf.json.JSONArray.fromObject (jsonarray.java:105) at Com.you.model.ListToJSON.main (listtojson.java:29) caused By:java.lang.ClassNotFoundException:org.apache.commons.collections.map.ListOrderedMapat Java.net.URLClassLoader $1.run (urlclassloader.java:366) at Java.net.urlclassloader$1.run (urlclassloader.java:355) at Java.security.AccessController.doPrivileged (Native Method) at Java.net.URLClassLoader.findClass ( urlclassloader.java:354) at Java.lang.ClassLoader.loadClass (classloader.java:425) at sun.misc.launcher$ Appclassloader.loadclass (launcher.java:308) at Java.lang.ClassLoader.loadClass (classloader.java:358) ... 5 more
2. Cause of error
/** * Convert List to JSON */package com.you.model;import java.util.arraylist;import Java.util.list;import net.sf.json.jsonarray;/** * @author Youhaidong * */public class Listtojson {/** * @param args */public static void main (St Ring[] args) {list<string> List = new arraylist<string> () List.add ("Spring"); List.add ("Summer"); List.add ("Autumn"); List.add ("Winter"); Jsonarray Jsonarray = jsonarray.fromobject (list); System.out.println ("list converted to JSON:" + jsonarray.tostring ());}}
from "caused By:java.lang.ClassNotFoundException:org.apache.commons.collections.map.ListOrderedMap" you can see that the missing jar
3. Solutions
Copy "Commons-collections-3.1.jar" to the Lib directory
List in Java converted to JSON error (iv)