0
    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?

Mium
  • 303
  • 1
  • 2
  • 12
  • Examine LogCat. Is anything getting logged from your `e.printStackTrace()`? – CommonsWare Nov 11 '18 at 13:50
  • @CommonsWare Nothing Special.. – Mium Nov 11 '18 at 14:01
  • @CommonsWare is there anything different on handling url inputstream from previous APIs? – Mium Nov 11 '18 at 14:18
  • No, though there may be issues with what your URL is. What is your URL? – CommonsWare Nov 11 '18 at 14:36
  • @CommonsWare it works perfectly on Android 8.1. I don't think the URL is the problem. – Mium Nov 11 '18 at 14:56
  • Well, there certainly were changes in Android 9.0, such as [these](https://developer.android.com/about/versions/pie/android-9.0-changes-28#framework-security-changes), which might affect your choice of URL. Beyond that, you will need to step through your code in a debugger and see what is going on. – CommonsWare Nov 11 '18 at 15:03
  • @CommonsWare I solved this: https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie/51902630 It was the answer – Mium Nov 12 '18 at 07:50

0 Answers0