OpenTracks: Export/Import file error for KMZ (with photos) files
Describe the bug
- When exporting
KMZ(with photos) files from OpenTracks, some files generate parser errors. When attempting to import these same files back into the app, the errors persist. This issue appears to be version-specific, as it doesn’t occur inv4.17.8and below - Additionally, sharing these files to Organic Maps fails with a “failed to load bookmarks” error message. While Organic Maps doesn’t support photo markers (expected behavior), KMZ files with photos should still load with the track data visible but without markers. Instead, these files fail completely, suggesting a file format issue rather than just the photo marker limitation.
To Reproduce
- Export track data to KMZ (with photos) format
- Attempt to import the KMZ (with photos) files back into OpenTracks
- Alternatively, try sharing the exported KMZ (with photos) files to Organic Maps
Error Messages
- When importing back to OpenTracks:
<file-name>.kmz: Parser error:
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found
- When sharing to Organic Maps:
"Failed to load bookmarks. The file may be corrupted or defective"
When share KMZ to Organic Maps from OpenTracks crash log
### App information * ID: de.dennisguse.opentracks.nightly * Version: 6121 v4.19.1Device information
- Brand: Redmi
- Device: alioth
- Model: M2012K11AC
- Id: AQ3A.240912.001
- Product: alioth
Firmware
- SDK: 35
- Release: 15
- Incremental: OS2.0.5.0.VNKCNXM
Cause of error
Exception in thread "AsyncTask #1": java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$4.done(AsyncTask.java:415)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:381)
at java.util.concurrent.FutureTask.setException(FutureTask.java:250)
at java.util.concurrent.FutureTask.run(FutureTask.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1251)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:668)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'float java.lang.Float.floatValue()' on a null object reference
at de.dennisguse.opentracks.io.file.exporter.KMLTrackExporter.getHeading(KMLTrackExporter.java:478)
at de.dennisguse.opentracks.io.file.exporter.KMLTrackExporter.writeMarker(KMLTrackExporter.java:277)
at de.dennisguse.opentracks.io.file.exporter.KMLTrackExporter.writeMarkers(KMLTrackExporter.java:151)
at de.dennisguse.opentracks.io.file.exporter.KMLTrackExporter.writeTrack(KMLTrackExporter.java:116)
at de.dennisguse.opentracks.io.file.exporter.KMZTrackExporter.writeTrack(KMZTrackExporter.java:74)
at de.dennisguse.opentracks.data.ShareContentProvider.lambda$openFile$3(ShareContentProvider.java:216)
at de.dennisguse.opentracks.data.ShareContentProvider$$ExternalSyntheticLambda5.writeDataToPipe(D8$$SyntheticClass:0)
at android.content.ContentProvider$1.doInBackground(ContentProvider.java:2572)
at android.os.AsyncTask$3.call(AsyncTask.java:394)
at java.util.concurrent.FutureTask.run(FutureTask.java:264)
... 3 more
Screenshots
Technical information
- Device: Poco F3
- OS: Android 15 | HyperOS
2.0.5.0(custom ROM) - OpenTracks version:
v4.19.0stable (playstore) orv4.19.1Nightly (6121), all from fdroid - OpenTracks commit id (only for nightly builds):
6121?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 23 (10 by maintainers)
Commits related to this issue
- Add logging for export failures. Part of #2096. — committed to OpenTracksApp/OpenTracks by dennisguse a year ago
- Add logging for export failures. Part of #2096. — committed to OpenTracksApp/OpenTracks by dennisguse a year ago
- Bugfix: KML/KMZ failed to export heading - ancient functionality got removed. Fixes #2096. — committed to OpenTracksApp/OpenTracks by dennisguse a year ago
- Bugfix: KML/KMZ failed to export heading - ancient functionality got removed. Fixes #2096. — committed to OpenTracksApp/OpenTracks by dennisguse a year ago
Hello Dennis,
This is the problem and maybe even a solution. I mean the solution works, now whether it’s a good one, you should decide that. I’ll write the entire summary and fix, maybe it will help.
Problem Summary
When exporting tracks with photo markers in KMZ with photos format on some devices, the export fails and the resulting file is unusable. The logcat shows a crash:
Root Cause
getHeadingmethod ofKMLTrackExporter.java.position.bearing().position.bearing()returnsnull(meaning the direction cannot be determined, e.g., due to missing or insufficient GPS data).float, which causes aNullPointerExceptionwhen the value isnull.Why This Affects KMZ with Photos Export
KMLTrackExporter) and then packages it with the photos.null, the app crashes during KML generation, so the KMZ export fails.What Was Changed and Why
File Modified:
src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.javaMethod:
private float getHeading(Track.Id trackId, Position position)Original Code:
Problem:
position.bearing()isnull, this code tries to returnnullas afloat, causing a crash.Fixed Code:
What the Fix Does:
position.bearing()isnull.0f(float zero) as a safe default, which means “north” in navigation terms.Summary
KMLTrackExporter.nullbearings by returning0f.No problem. I’ll install it when it becomes available and post the logcat here again.
Thanks for investigating this issue.
This only affects KMZ files with photo markers - standard KML, GPX, and KMZ without photos export correctly.
Looking at the problematic KMZ exports, it seems the
imagesdirectory is completely missing, containing only thedoc.kmlfile inside the zip archive. In contrast, exports fromv4.17.8properly include theimagesdirectory for KMZ files with photo markers.