westnordost / osmapi

Java client for the OSM API 0.6
GNU Lesser General Public License v3.0
97 stars 19 forks source link

Getting de.westnordost.osmapi.common.errors.OsmApiReadResponseException: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG </node>@4:164 in java.io.InputStreamReader@1a160b5e when trying to obtain the node #13

Closed Eljah closed 7 years ago

Eljah commented 7 years ago

I have a

    MapDataHandler mapDataHandler = new MapDataHandler() {
        public void handle(BoundingBox boundingBox) {
        }

        public void handle(Node node) {
            if (node.getTags().get("highway").equals("bus_stop")) {
            //    System.out.println(node.getTags().get("name"));
            //    System.out.println(node.getTags().get("name:tt"));
            //    System.out.println(node.getTags().get("name:ru"));
            //    System.out.println(node.getTags().get("name:en"));
            }
        }

        public void handle(Way way) {
        }

        public void handle(Relation relation) {
            if (relation.getTags().get("type").equals("route")) {
                if (relation.getTags().get("route").equals("bus")) {
                    System.out.println(relation.getTags().get("name"));
                    busRoutes.put(relation.getTags().get("name"), relation);
                }
            }

        }
    };

When the osm data is processed whti this particular handler I'm getting the following error:

de.westnordost.osmapi.common.errors.OsmApiReadResponseException: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG @4:164 in java.io.InputStreamReader@1a160b5e

westnordost commented 7 years ago

The exception has nothing to do with your code, it happens earlier - while parsing the XML. It says that the XML returned by the API (you use) is invalid.

westnordost commented 7 years ago

It would be helpful to see what call you actually make with your mapDataHandler.

Eljah commented 7 years ago

Ok, the call occurs in this cli programm:

import de.westnordost.osmapi.OsmConnection; import de.westnordost.osmapi.map.MapDataDao; import de.westnordost.osmapi.map.data.*; import de.westnordost.osmapi.map.handler.MapDataHandler; import org.fit.cssbox.demo.PdfImageRenderer; import org.xml.sax.SAXException;

import java.awt.; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.lang.reflect.Member; import java.util.; import java.util.List;

/**

and on public void handle(Node node) { if (node.getTags().get("highway").equals("bus_stop

I'm getting de.westnordost.osmapi.common.errors.OsmApiReadResponseException: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG @4:164 in java.io.InputStreamReader@5dc21014 and so on

westnordost commented 7 years ago

I did not ask for your source code. I asked for what HTTP call you actually make.

OsmConnection line 267: What URL cannot be parsed?

By the way, you should really consider using Overpass for things like that. Overpass answers are the same format as OSM Api answers, so you can still use this library for that.

westnordost commented 7 years ago

Oh man, what a waste of time. I copy-pasted your code into a new project and executed it, removed your "exception handling" and got the full stack trace.

Exception in thread "main" de.westnordost.osmapi.common.errors.OsmApiReadResponseException: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG </node>@4:164 in java.io.InputStreamReader@26a1ab54
    at de.westnordost.osmapi.OsmConnection.handleResponse(OsmConnection.java:322)
    at de.westnordost.osmapi.OsmConnection.makeRequest(OsmConnection.java:191)
    at de.westnordost.osmapi.OsmConnection.makeRequest(OsmConnection.java:142)
    at de.westnordost.osmapi.map.MapDataDao.getMap(MapDataDao.java:194)
    at ConnectionTester.main(ConnectionTester.java:65)
Caused by: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG </node>@4:164 in java.io.InputStreamReader@26a1ab54
    at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:64)
    at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:58)
    at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:20)
    at de.westnordost.osmapi.OsmConnection.handleResponse(OsmConnection.java:314)
    ... 4 more
Caused by: java.lang.NullPointerException
    at ConnectionTester$1.handle(ConnectionTester.java:36)
    at de.westnordost.osmapi.map.MapDataParser.onEndElement(MapDataParser.java:152)
    at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:49)
    ... 7 more

Note the cause, this is in your code. Elements that do not have tags return null for getTags().