Я пытаюсь разобрать xml и получаю NullPointerException
, но я не могу понять, что я сделал не так:
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;
}
и вызывающий абонент:
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();
}