我正在開發一個應用程序,在我的應用程序中,我使用DOM
XML解析顯示大量圖像,它工作正常,但有時我在我的xml解析處理程序中得到了org.xml.sax.SAXParseException: Unexpected end of the document
。如何解決此問題,請幫助me.This是我的XML解析處理程序代碼如何在android中解決SAXParseExecption?
public String parse_bannerlink() throws UnknownHostException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
String bannerlink=null;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(this.getInputStream());
org.w3c.dom.Element root = dom.getDocumentElement();
NodeList items = root.getElementsByTagName("partypicbanner");
for (int i = 0; i < items.getLength(); i++) {
Node item = items.item(i);
NodeList properties = item.getChildNodes();
for (int j = 0; j < properties.getLength(); j++) {
Node property = properties.item(j);
String name = property.getNodeName();
if (name.equalsIgnoreCase("link")) {
bannerlink=property.getFirstChild().getNodeValue();
}
}}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return bannerlink;
}
感謝所有
@Thanks屋大維Damiean,我編輯,請檢查我的代碼 – JohnNick 2010-11-19 11:29:00