0
我在使用Simple Xml Serializer從我的android項目中的複雜對象構建消息時遇到問題。奇怪的是,它昨天運行良好;序列化的對象被寫入一個StringWriter,一切都很好。由於某種原因,我現在得到這個:神祕的空指針異常與簡單的XML serializer.write
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);
javadoc for persister接口:http://simple.sourceforge.net/download/stream/doc/javadoc/org/simpleframework/xml/Serializer.html – Jacob 2011-03-08 18:24:28
不應該在使用它之前初始化StringWriter嗎? – MByD 2011-03-08 18:27:46
確實... * facepalm * – Jacob 2011-03-08 18:45:09