Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java xstream原语反序列化不';不行?_Java_Xml Serialization_Xstream - Fatal编程技术网

Java xstream原语反序列化不';不行?

Java xstream原语反序列化不';不行?,java,xml-serialization,xstream,Java,Xml Serialization,Xstream,我正在使用XStream序列化程序来序列化一个原语,并面临反序列化它的问题。以下是问题描述: 我有: int i = 80; 我将其序列化如下: serializer.toXML(i, new FileOutputStream("me.xml")); 并获取此xml的名称: <int>80</int> 我得到这样的例外: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1

我正在使用XStream序列化程序来序列化一个原语,并面临反序列化它的问题。以下是问题描述:

我有:

int i = 80;
我将其序列化如下:

serializer.toXML(i, new FileOutputStream("me.xml"));  
并获取此xml的名称:

<int>80</int>
我得到这样的例外:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at com.thoughtworks.xstream.core.util.FastStack.pop(FastStack.java:42)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:125)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
    at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63)
    at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:912)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:903)
    at Utilities.Parser.serializeTimeIntervalDuration(Parser.java:371)
    at Utilities.Parser.parseData(Parser.java:152)
    at CoreLayer.Main.Main.main(Main.java:52)  
线程“main”java.lang.ArrayIndexOutOfBoundsException中的异常:-1 位于com.thoughtworks.xstream.core.util.FastStack.pop(FastStack.java:42) 位于com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:125) 位于com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103) 位于com.thoughtworks.xstream.io.xml.XppReader.(XppReader.java:63) 位于com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54) 位于com.thoughtworks.xstream.xstream.fromXML(xstream.java:912) 位于com.thoughtworks.xstream.xstream.fromXML(xstream.java:903) 位于Utilities.Parser.serializeTimeIntervalDuration(Parser.java:371) Parser.parseData(Parser.java:152) 位于CoreLayer.Main.Main.Main(Main.java:52) 有人能指出我的错误吗


提前谢谢

这是因为
fromXML()
需要的是XML,而不是文件名。在解析XML之前,应该先从文件中读入XML

注意,它有多个fromXML()的实现,因此您可以提供字符串、URL、读取器等


目前XStream正试图理解字符串“me.xml”。

这是因为
fromXML()
需要的是xml,而不是文件名。在解析XML之前,应该先从文件中读入XML

注意,它有多个fromXML()的实现,因此您可以提供字符串、URL、读取器等


目前XStream正试图理解字符串“me.xml”。

Brian,非常感谢,这节省了我很多时间。我真的很感激!布莱恩,非常感谢,这节省了我很多时间。我真的很感激!
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    at com.thoughtworks.xstream.core.util.FastStack.pop(FastStack.java:42)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:125)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
    at com.thoughtworks.xstream.io.xml.XppReader.<init>(XppReader.java:63)
    at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:912)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:903)
    at Utilities.Parser.serializeTimeIntervalDuration(Parser.java:371)
    at Utilities.Parser.parseData(Parser.java:152)
    at CoreLayer.Main.Main.main(Main.java:52)