Hi everyone,
I'm trying to read a TreeMap from an XML file using XStream (I previously
created the XML file using XStream too) in my Android application.
I simply do this in a static method of a class:
File f = new File(Environment.getExternalStorageDirectory(), "map.xml");
XStream xStream = new XStream(new DomDriver());
@SuppressWarnings("unchecked")
TreeMap<String,Object> map = (TreeMap<String,Object>) xStream.fromXML(f);
and then I use the values from the TreeMap with no problems... the first
time.
The thing is, if I invoke the method for a second time, it doesn't matter
if I do it just after the first execution or after a while, I get this:
05-24 08:33:53.404: E/AndroidRuntime(15543): FATAL EXCEPTION: main
05-24 08:33:53.404: E/AndroidRuntime(15543):
com.thoughtworks.xstream.converters.ConversionException: null : null
05-24 08:33:53.404: E/AndroidRuntime(15543): ---- Debugging information ----
05-24 08:33:53.404: E/AndroidRuntime(15543): cause-exception :
java.lang.NullPointerException
05-24 08:33:53.404: E/AndroidRuntime(15543): cause-message : null
05-24 08:33:53.404: E/AndroidRuntime(15543): class :
java.util.TreeMap
05-24 08:33:53.404: E/AndroidRuntime(15543): required-type :
java.util.TreeMap
05-24 08:33:53.404: E/AndroidRuntime(15543): converter-type :
com.thoughtworks.xstream.converters.collections.TreeMapConverter
05-24 08:33:53.404: E/AndroidRuntime(15543): path : /tree-map
05-24 08:33:53.404: E/AndroidRuntime(15543): version : 0.0
05-24 08:33:53.404: E/AndroidRuntime(15543): -------------------------------
05-24 08:33:53.404: E/AndroidRuntime(15543): at
com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
05-24 08:33:53.404: E/AndroidRuntime(15543): at
com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
[...]
05-24 08:33:53.404: E/AndroidRuntime(15543): Caused by:
java.lang.NullPointerException
05-24 08:33:53.404: E/AndroidRuntime(15543): at
java.util.TreeMap.find(TreeMap.java:277)
05-24 08:33:53.404: E/AndroidRuntime(15543): at
java.util.TreeMap.putInternal(TreeMap.java:240)
05-24 08:33:53.404: E/AndroidRuntime(15543): at
java.util.TreeMap.put(TreeMap.java:186)
05-24 08:33:53.404: E/AndroidRuntime(15543): at
java.util.AbstractMap.putAll(AbstractMap.java:381)
05-24 08:33:53.404: E/AndroidRuntime(15543): at
com.thoughtworks.xstream.converters.collections.TreeMapConverter.populateTreeMap(TreeMapConverter.java:150)
[...]
with the same file. In fact, if I try to read the file and then pass it to
XStream as a String, I get the same exception (but the XML String is
created OK).
Does anyone know what the cause could be or has experienced the same
problem and know how to fix it?
Thanks!
Gonzalo Rodríguez Píriz.