使用Simple XML serializer.write的神秘Null Pointer异常

时间:2011-03-08 18:22:58

标签: java android simple-framework

我在使用Simple Xml Serializer从我的android项目中的复杂对象构建消息时遇到问题。奇怪的是,它昨天运作良好;序列化对象被写入StringWriter,一切都很顺利。出于某种原因,我现在得到了这个:

03-08 12:01:12.884: WARN/System.err(444): java.lang.NullPointerException
   at org.simpleframework.xml.core.Traverser.write(Traverser.java:225)
   at org.simpleframework.xml.core.Traverser.write(Traverser.java:208)
     at org.simpleframework.xml.core.Traverser.write(Traverser.java:186)
   at org.simpleframework.xml.core.Persister.write(Persister.java:1187)
    at org.simpleframework.xml.core.Persister.write(Persister.java:1169)
    at org.simpleframework.xml.core.Persister.write(Persister.java:1147)

它继续炸毁serializer.write()行,我无法弄清楚原因。

//xmlMsg is the object to be serialized.
Serializer serializer = new Persister();
StringWriter outMsg = null;
serializer.write(xmlMsg, outMsg);

1 个答案:

答案 0 :(得分:2)

从javadoc来看,我觉得该方法会尝试写入Writer参数,因此它不应该是null