jenetics / jpx

JPX - Java GPX library
Apache License 2.0
202 stars 30 forks source link

Writing GPX error #31

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hello,

when trying to write a GPX file I get an error.

I found a fix to simply add the encoding "UTF-8" when creating the XMLStreamWriter in the GPX.java class, starting from line 1075:

try {
    final XMLStreamWriter writer = indent != null
        ? new IndentingXMLWriter(
            factory.createXMLStreamWriter(output, "UTF-8"), indent)
        : factory.createXMLStreamWriter(output, "UTF-8");

    writer.writeStartDocument("UTF-8", "1.0");
    gpx.write(writer);
    writer.writeEndDocument();

The error message i got before adding the encoding:

java.io.IOException: javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1252' and input paramter for writeStartDocument() method 'UTF-8' do not match.
    at io.jenetics.jpx.GPX.write(GPX.java:1085)
    at io.jenetics.jpx.GPX.write(GPX.java:1021)
    at io.jenetics.jpx.GPX.write(GPX.java:1039)
    at io.jenetics.jpx.GPX.write(GPX.java:1053)
    at org.sonnenwagen.spark.gps.GPXhandler.updateOrSetNewWayPoint(GPXhandler.java:56)
    at org.sonnenwagen.spark.gps.GPXhandler.main(GPXhandler.java:31)
Caused by: javax.xml.stream.XMLStreamException: Underlying stream encoding 'Cp1252' and input paramter for writeStartDocument() method 'UTF-8' do not match.
    at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeStartDocument(Unknown Source)
    at io.jenetics.jpx.GPX.write(GPX.java:1081)
    ... 5 more

Best regards

jenetics commented 6 years ago

Merged into r1.1.3.