I am just starting to experiment with Android Development using SimpleXML and I thought that everything was going well until I got hooked. The code below throws an exception
W / System.err (665): org.simpleframework.xml.core.ConstructorException: cannot create inner class
I looked at the questions on inner classes and I think I understand why you used them (not that mine was necessarily intentional), but despite the fact that I moved around the code to avoid using it, I'm still a little stuck and appreciate any help.
Source:
public class InCaseOfEmergencyMedAlertAllergiesActivity extends Activity { public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); Serializer serializer = new Persister(); InputStream xmlstream = this.getResources().openRawResource(R.raw.sample_data_allergies); try { medalertdata allergyObject = serializer.read(medalertdata.class, xmlstream); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } setContentView(R.layout.allergies); } @Root public class medalertdata { @ElementList private List<allergy> allergyList; public List getAllergies() { return allergyList; } } @Root public class allergy{ @Element private String to; @Element private Boolean medical; @Element private String notes; public allergy(String to, Boolean medical, String notes){ this.to = to; this.medical = medical; this.notes = notes; } public String getTo() { return to; } public Boolean getMedical() { return medical; } public String getNotes() { return notes; } }
}
With the referenced XML file:
<?xml version="1.0" encoding="ISO-8859-1"?> <medalertdata> <allergy> <to>Penicillin</to> <medical>true</medical> <notes></notes> </allergy> <allergy> <to>Bee Stings</to> <medical>false</medical> <notes>Sample</notes> </allergy> </medalertdata>
Is there a problem with the way I annotated SimpleXML classes or where I am trying to read them? Thank you
Rory
source share