Exception with Simple XML framework deserialization
No-Arg Constructor
I don't know this particular XML framework, but, usually you need a constructor that takes no parameters/arguments for each class that you wish to be deserialized. Such constructors are known as a "no-arg", "0-argument", or (formally) nullary constructor.
Otherwise, the framework cannot instantiate the class.
You don't have to delete things from constructor. You can just add something like this:
public Contact(@Element (name = "id") String id, @Element (name = "name") String name) {...
It was working for me :)
I think it is better to use SAX for parsing an XML this is an example of parsing:
You need to create a class parser like this:
{ public class DataXMLReader extends DefaultHandler { public DataXMLReader() { } public void startElement(String uri, String name, String qName,Attributes atts) { if (name.trim().equalsIgnoreCase("window")) { atts.getValue("type_id") // to get proprietis } else if (name.trim().equalsIgnoreCase("component")) { } } public void endElement(String uri, String name, String qName) throws SAXException { if (name.trim().equalsIgnoreCase("component")) { if(Integer.parseInt(typeid)<=6) idParent.remove(idParent.size()-1); } } @Override public void startDocument() throws SAXException { // TODO Auto-generated method stub super.startDocument(); Log.e("StartDoc","Reading XML"); } public void endDocument() throws SAXException { // TODO Auto-generated method stub myBdd.close(); Log.e("EndtDoc","End XML"); }}}
and this is an example to call XML from URL:
String url="http://vxbfdhbf.xml"; try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); URL sourceUrl = new URL(url); HttpURLConnection connection = null; connection = (HttpURLConnection)sourceUrl.openConnection(); connection.setConnectTimeout(60000); connection.setInstanceFollowRedirects(false); connection.connect(); DataXMLReader myXMLHandler = new DataXMLReader(this,"1"); xr.setContentHandler(myXMLHandler); xr.parse(new InputSource(connection.getInputStream())); connection.disconnect(); } catch (Exception e) { Log.e("saxERR",""+e.toString()); }