On Thu, May 24, 2012 at 4:23 PM, Jörg Schaible
<[email protected]>wrote:

> Hi Gonzalo,
>
> Gonzalo Rodríguez Píriz wrote:
>
> > 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?
>
> Basically, if you can read it once, you should be able to read it twice.
> ;-)
>
> Can you try to reproduce this outside of Android? The TreeMapConverter does
> some really ugly hacks though. Do you use an own Comparator? Do your
> elements in the Map contain (indirect) references on the Map itself?
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Thank you Jörg,

yes, that was what I though too :D

Definitely it's a problem with the TreeMap, I replaced it with a HashMap
and now it works all the time. Anyway, the TreeMap was very simple, I
didn't use a comparator and it didn't had any references, only pairs
key-value with Boolean, Integer and String values. If you want me to I can
try to reproduce it outside Android later and see if it crashes too.

Thanks for the help :)

Gonzalo.

Reply via email to