tawfiqdawod / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

RecordedRouteGPXFormatter throws Exception and stores gpx file anyway #406

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. try to store recorded points to gpx file in onDestroy() method
2. assert recordedGeoPoints is not empty

Exception is thrown but the gpx file is created anyway.

02-21 12:38:03.576: E/OPENSTREETMAP(17361): File-Writing-Error
02-21 12:38:03.576: E/OPENSTREETMAP(17361): java.lang.IllegalArgumentException: 
Records size == 0
02-21 12:38:03.576: E/OPENSTREETMAP(17361):     at 
org.osmdroid.contributor.util.RecordedRouteGPXFormatter.create(RecordedRouteGPXF
ormatter.java:94)
02-21 12:38:03.576: E/OPENSTREETMAP(17361):     at 
org.androad.osm.api.traces.GPXToFileWriter$1.run(GPXToFileWriter.java:64)
02-21 12:38:03.576: E/OPENSTREETMAP(17361):     at 
java.lang.Thread.run(Thread.java:1019)

used method provided below.
this method is used in AndRoad

public static void writeToFileAsync(final ArrayList<RecordedGeoPoint> 
recordedGeoPoints){
        new Thread(new Runnable(){
            @Override
            public void run() {
                try {
                    // Ensure folder exists
                    final String traceFolderPath = Util.getAndRoadExternalStoragePath() + SDCARD_SAVEDTRACES_PATH;
                    new File(traceFolderPath).mkdirs();

                    // Create file and ensure that needed folders exist.
                    final String filename = SDF.format(new Date(System.currentTimeMillis())) + ".gpx";
                    final File dest = new File(traceFolderPath + filename + ".zip");

                    // Write Data
                    final OutputStream out = new BufferedOutputStream(new FileOutputStream(dest),StreamUtils.IO_BUFFER_SIZE);
                    final byte[] data = org.androad.osm.api.traces.util.Util.zipBytes(RecordedRouteGPXFormatter.create(recordedGeoPoints).getBytes(), filename);

                    out.write(data);
                    out.flush();
                    out.close();
                } catch (final Exception e) {
                    Log.e(OSMConstants.DEBUGTAG, "File-Writing-Error", e);
                }
            }
        }, "GPXToFileSaver-Thread").start();
    }

Original issue reported on code.google.com by temporar...@gmail.com on 21 Feb 2013 at 12:18

GoogleCodeExporter commented 8 years ago
Forget it. Its an issue in superclass in AndRoad.

Original comment by temporar...@gmail.com on 21 Feb 2013 at 8:19

GoogleCodeExporter commented 8 years ago

Original comment by neilboyd on 21 Feb 2013 at 10:01