【发布时间】:2017-11-02 23:10:52
【问题描述】:
我正在尝试以字符串格式创建一个简单的 XML,但我似乎无法让 Eclipse 一起玩,因为它一直给我一个“无法从 void 转换为字符串”的错误警告(我跟着这个 @987654321 @.) 这是我的示例代码:
final Xstream xstream = new Xstream();
final Person myPerson = new Person();
Writer writer = new StringWriter();
try {
writer.write("<?xml version=\"1.0\"?>");
} catch (final IOException e) {
e.printStackTrace();
System.exit(0); //just for testing sakes
}
final String xmlResponse = xstream.toXML(myPerson, writer); // the line that has the error in Eclipse
对于“也许您实际上并没有为 myPerson 创建对象”的明显答案,我为 Person 提供的代码是:
public class Person{
public final String name;
Person(){
name = "EmptyName";
}
}
我已经搜索了文档,但没有发现任何有关此错误的信息。但是,Xstream 的源代码中有 void toxml(Xstream, Object, Writer) 方法,这可能是问题所在。另一件事可能是转义字符串中的引号也可能是问题,但我没有办法解决这个问题。加上删除引号和转义并不能解决问题。
任何解决此问题的帮助将不胜感激。 Xstream 版本 1.4.10 以防万一。
【问题讨论】: