I'm trying to use XStream to (de)serialize a HashMap of some of my own classes in an Android app. For example, one of the classes is Word, which has the following variables:
private String word;
private boolean capitalizable;
private int useCount;
private HashMap<Character,Integer> endPunctuation;
private HashSet<String> nextWritables;
I already have the whole set up working in a standard java application, i'm just trying to wrap it all in an android UI (which works fine). Serializing works fine in Android. The problem I'm having is when I deserialize, i get the following error:
com.thoughtworks.xstream.converters.ConversionException: Cannot construct chatai.Word as it does not have a no-args constructor : Cannot construct chatai.Word as it does not have a no-args constructor
---- Debugging information ----
message : Cannot construct chatai.Word as it does not have a no-args constructor
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct chatai.Word as it does not have a no-args constructor
class : java.util.HashMap
required-type : chatai.Word
path : /map/entry/chatai.Word
line number : 1
-------------------------------
I get this error if I use any version of XStream other than 1.4.1 on my desktop application. I get the error always on my android application, no matter the verison of XStream. I'm sure that the desktop one has that issue because it's running on Java 7. I'm not sure about android. It has something to do with reflection, due to this warning when adding the xstream-1.4.1.jar:
[2011-09-07 21:06:52 - DroidBot] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.thoughtworks.xstream.XStream$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
A quick test shows me that serializing and deserializing a String object in Android works fine. How can I get rid of that error?