Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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时的ArrayIndexOutOfBoundsException_Java_Xml_Xstream - Fatal编程技术网

Java 使用XStream时的ArrayIndexOutOfBoundsException

Java 使用XStream时的ArrayIndexOutOfBoundsException,java,xml,xstream,Java,Xml,Xstream,我甚至不确定这怎么可能,但我正在运行的程序给了我一个奇怪的错误。我得到了一个ArrayIndexOutOfBoundsException:-1对一个循环。整个错误如下: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1 at com.thoughtworks.xstream.core.util.OrderRetainingMap.entrySet(OrderRetainingMap.java:77) a

我甚至不确定这怎么可能,但我正在运行的程序给了我一个奇怪的错误。我得到了一个ArrayIndexOutOfBoundsException:-1对一个循环。整个错误如下:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at com.thoughtworks.xstream.core.util.OrderRetainingMap.entrySet(OrderRetainingMap.java:77)
at java.util.HashMap.putMapEntries(HashMap.java:511)
at java.util.HashMap.putAll(HashMap.java:784)
at com.thoughtworks.xstream.core.util.OrderRetainingMap.<init>(OrderRetainingMap.java:36)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.buildMap(FieldDictionary.java:135)
at com.thoughtworks.xstream.converters.reflection.FieldDictionary.fieldsFor(FieldDictionary.java:76)
at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:126)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:81)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:895)
at com.thoughtworks.xstream.XStream.marshal(XStream.java:884)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:857)
at com.thoughtworks.xstream.XStream.toXML(XStream.java:844)
at unl.cse.assignments.DataConverter.output(DataConverter.java:210)
at unl.cse.assignments.DataConverter.main(DataConverter.java:121)
(第121行仅调用输出)


我已经调查这个错误很长时间了,我无法找出它的原因。我认为xstream有问题,但我尝试了其他输出。

正如Andreas指出的,这实际上是一个在1.4.6版中修复的问题。可以下载最新版本的XStream。

我会检查p object contents->其中一个应该有问题。或者xstream有一个问题p(产品)的内容实际上是产品的子类。这可能是一个潜在的问题吗?可能是1.4.6中修复的一个bug:这个问题与foreach循环无关。也许改变标题和问题?@Tanner那么你应该回答自己的问题并接受这个答案。XStream的某个版本有一个bug可能很有用。
for(Product p : products)
    {
        if(AwardTicket.class.isInstance(p)){
            xstream.alias("awardTicket", AwardTicket.class);
            pw.print(xstream.toXML(p) + "\n");
        }
}