NoClassDefFoundError

//Java对象转化json格式
    public static void toJsonByJettisonMappedXmlDriver(){
        try {
            User user = getUser();
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            OutputStreamWriter ow = new OutputStreamWriter(fileOutputStream, Charset.forName("UTF-8"));
            xstream = new XStream(new JettisonMappedXmlDriver());
            xstream.setMode(XStream.NO_REFERENCES);
            xstream.alias("user", User.class);
            xstream.toXML(user,ow);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

在xstream初始化时报错

查找源码

在new JettisonMapperdXmlDriver()对象时 其构造器如下

原因找到了  类org.codehaus.jetttison.mapped.Configuration没找到

java.lang.NoClassDefFoundError此异常与java.lang.ClassNotFoundException区别在于前者是在运行期异常后者是在编译期异常

 

posted @ 2016-11-30 09:27  蟹丸  阅读(...)  评论(... 编辑 收藏