try {
hashMap = new HashMap<>();
InputStream inputStream;
URL url = new URL(params[0]);
inputStream = url.openStream();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(inputStream);
Element element = document.getDocumentElement();
element.normalize();
NodeList nodeList = document.getElementsByTagName("string");
for (int current = 0; current < nodeList.getLength(); current++) {
Node node = nodeList.item(current);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element_specific = (Element) node;
hashMap.put(element_specific.getElementsByTagName("one").item(0).getChildNodes().item(0).getNodeValue(), element_specific.getElementsByTagName("two").item(0).getChildNodes().item(0).getNodeValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}
I am trying to parse an XML file using InputStream and DocumentBuilder. It works perfectly on from API Level 23 to API Level 27, but when I execute the application on targetApi:28 and Android 9 Pie, it doesn't work and I only get the result: null.
I don't know why it happens. What's the problem?