带有简单 XML serializer.write 的神秘空指针异常

发布于 2024-10-21 01:25:27 字数 932 浏览 1 评论 0原文

我在使用 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);

I'm having trouble using Simple Xml Serializer to build a Message from a complex object in my android project. The strange part is that it worked fine yesterday; the serialized object was written to a StringWriter and all was well. For some reason I now get this:

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)

It keeps blowing up on the serializer.write() line and I can't figure out why.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久夏青 2024-10-28 01:25:27

从 javadoc 看来,该方法将尝试写入 Writer 参数似乎是合理的,因此它不应该是 null

From the javadoc it seems reasonable to me that the method will attempt to write to the Writer parameter, thus it shouldn't be null.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文