I’m trying to parse some xml and i’m getting a NullPointerException but i can’t seem to figure out what i did wrong:
private Puzzle XMLfromFile(int xml) throws ParserConfigurationException, SAXException, IOException {
SAXParserFactory spf= SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
XMLHandler theHandler= new XMLHandler();
xr.setContentHandler(theHandler);
InputStream is = getResources().openRawResource(xml);
xr.parse(new InputSource(is)); //this crashes the program with the null pointer
return theHandler.currentPuzzle;
}
and the caller:
try {
thePuzzle=XMLfromFile(R.raw.puzzle1);
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
Sorry i need to sleep over my problems a little more often, i found out that a code snipit i deleted cause my handler to throw the null pointer problem. Thanks you, and again sorry.