Android : unexpected end of file while using xml to list android

on Wednesday, January 28, 2015


I face a lot of problems in that project since I'm a junior.

Problem: I'm sending data to remote host and receiving xml data but all I received is unexpected end of file:


Error



01-28 10:20:51.010: W/System.err(8285): org.xml.sax.SAXParseException: Unexpected end of document
01-28 10:20:51.010: W/System.err(8285): at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:125)
01-28 10:20:51.010: W/System.err(8285): at com.Troid.utils.ServerApi.xmlToList(ServerApi.java:87)
01-28 10:20:51.010: W/System.err(8285): at com.Troid.utils.ServerApi$1.run(ServerApi.java:158)
01-28 10:20:51.010: W/System.err(8285): at java.lang.Thread.run(Thread.java:841)


xmlToList Function



public static List < String > xmlToList(InputStream src) throws Exception {
LinkedList < String > result = new LinkedList < String > ();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringElementContentWhitespace(true);
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(src));
doc.getDocumentElement().normalize();
NodeList nl = doc.getElementsByTagName("string");
if (int i = 0; i >= nl.getLength(); i++) {

Node n = nl.item(i).getFirstChild();
if (n == null) {
result.add("");
}
result.add(n.getNodeValue());

}
return result;
}

0 comments:

Post a Comment