I’ve searched far and wide about this issue, tried many fixes but I cannot get any to work..
I’m trying to parse an xml file from my server, I can retrieve the file okay but when I go to parse it, it errors. Here is my code:
public final static Document parse(String xml){
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
// ERRORS HERE
is.setCharacterStream(new StringReader(xml));
//
doc = db.parse(is);
} catch (ParserConfigurationException e) {
System.out.println("XML parse error: " + e.getMessage());
return null;
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
System.out.println("I/O exeption: " + e.getMessage());
return null;
}
return doc;
}
and here is the error I’m getting:
12-02 20:26:22.340: E/AndroidRuntime(11600): java.lang.NullPointerException
12-02 20:26:22.340: E/AndroidRuntime(11600): at java.io.StringReader.<init>(StringReader.java:48)
12-02 20:26:22.340: E/AndroidRuntime(11600): at com.arayray.bootanimationutility.tablet.functions.DownloadFunctions.parse(DownloadFunctions.java:41)
And you are sure xml is not null?
That appears to be what the error is saying.