用 XStream 从 arraylist 写入 XML

Write XML from arraylist with XStream

我有 class Alm_datos,有一个数组列表,里面有一些员工:

public class Alm_datos  extends InputSource{

     static ArrayList<Empleado> listaEmpleados = new ArrayList<>();

另一个class,用xml

写入文件

public class Xstream {

Alm_datos alm = new Alm_datos();

public void xstreamSerializar() throws FileNotFoundException{

    XStream xs = new XStream();
    xs.alias("EmpleadoXS", Empleado.class);
    xs.toXML(alm.listaEmpleados , new leOutputStream("EmpleadosXS.xml"));

    }//END METODO

}//END CLASS

不过还不行:S

Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:369)
    at empleadosaleatorio.Xstream.xstreamSerializar(Xstream.java:18)
    at empleadosaleatorio.EmpleadosAleatorio.menu(EmpleadosAleatorio.java:150)
    at empleadosaleatorio.EmpleadosAleatorio.main(EmpleadosAleatorio.java:17)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 4 more

你有一个依赖问题..你在使用 maven 吗? 也许你缺少 xmlpull 库

<dependency> <groupId>xmlpull</groupId> <artifactId>xmlpull</artifactId> <version>1.1.3.1</version> </dependency>