我正在尝试解析在线XML文档,但是当我运行以下代码时,它会在get()
方法中返回NULL异常。我尝试进一步调试以实现输入流可能返回空值。谁知道什么是错的?
public class XMLHelper extends DefaultHandler{
private String URL_MAIN = "https://www.ura.gov.sg/LsmMap/xml/lsm-test.xml";
String TAG = "XMLHelper";
Boolean currTag = false;
String currTagVal = "";
private PostValue post ;
private ArrayList<PostValue> postsList = new ArrayList<PostValue>();
//to read the XML
public void get() {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser mSaxParser = factory.newSAXParser();
XMLReader mXmlReader = mSaxParser.getXMLReader();
mXmlReader.setContentHandler(this);
InputStream mInputStream = new URL(URL_MAIN).openStream();
mXmlReader.parse(new InputSource(mInputStream));
} catch (Exception e) {
Log.e(TAG, "Exception123: " + e.getMessage());
}
}
}