Java中的List转换成JSON报错(一)

1、错误描述

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(ClassLoader.java:800)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	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)
	at com.you.model.ListToJSON.main(ListToJSON.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
	at 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)
	... 13 more

2、错误原因

/**
 * 将List转换成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(String[] args) 
	{
		List list = new ArrayList();
		list.add("春天");
		list.add("夏天");
		list.add("秋天");
		list.add("冬天");
		
		JSONArray jsonArray = JSONArray.fromObject(list);
		
		System.out.println("List转换成JSON:" + jsonArray.toString());
	}

}

缺少Jar包


3、解决办法

   将“commons-lang-2.4.jar”复制到lib下

 

你可能感兴趣的:(Java,java,json,List)