File exists on sdcard - Why can't I load it??

419 views
Skip to first unread message

lele

unread,
Mar 29, 2015, 9:22:26 AM3/29/15
to mapsfo...@googlegroups.com
Hi is anybody having this issue?
Im' running the example in https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Android-App.md

It compiles fine but when it runs it complains it can't find the german.map file but it is definitely there. I also displayed a line checking if the map exists, and it confirms that file is there

private File getMapFile() {


        File file = new File(Environment.getExternalStorageDirectory(), MAPFILE);

       System.out.println("####################FILE EXISTS="+file.exists());

       return file;

   }


(See line 8, the file IS there)
 

I/ActivityManager(17752): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.maps/.FullscreenActivity (has extras)} from uid 10022 on display 0

I/ActivityManager(17752): Start proc com.example.maps for activity com.example.maps/.FullscreenActivity: pid=24573 uid=10142 gids={50142, 9997} abi=arm64-v8a

I/art     (24573): Late-enabling -Xcheck:jni

D/TILECACHE INMEMORY SIZE(24573): 36

D/TILECACHE FILECACHE SIZE(24573): 408

I/System.out(24573): ####################FILE EXISTS=true

E/MapFile (24573): null

E/MapFile (24573): org.mapsforge.map.reader.header.MapFileException: cannot read file: /storage/emulated/0/germany.map

E/MapFile (24573): at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:242)

E/MapFile (24573): at com.example.maps.FullscreenActivity.onStart(FullscreenActivity.java:209)

E/MapFile (24573): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)

E/MapFile (24573): at android.app.Activity.performStart(Activity.java:5949)

E/MapFile (24573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)

E/MapFile (24573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)

E/MapFile (24573): at android.app.ActivityThread.access$800(ActivityThread.java:144)

E/MapFile (24573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)

E/MapFile (24573): at android.os.Handler.dispatchMessage(Handler.java:102)

E/MapFile (24573): at android.os.Looper.loop(Looper.java:135)

E/MapFile (24573): at android.app.ActivityThread.main(ActivityThread.java:5221)

E/MapFile (24573): at java.lang.reflect.Method.invoke(Native Method)

E/MapFile (24573): at java.lang.reflect.Method.invoke(Method.java:372)

E/MapFile (24573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

E/MapFile (24573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

E/MapFile (24573): null

E/MapFile (24573): java.lang.NullPointerException: Attempt to invoke virtual method 'void org.mapsforge.map.reader.IndexCache.destroy()' on a null object reference

E/MapFile (24573): at org.mapsforge.map.reader.MapFile.closeFile(MapFile.java:289)

E/MapFile (24573): at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:258)

E/MapFile (24573): at com.example.maps.FullscreenActivity.onStart(FullscreenActivity.java:209)

E/MapFile (24573): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)

E/MapFile (24573): at android.app.Activity.performStart(Activity.java:5949)

E/MapFile (24573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)

E/MapFile (24573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)

E/MapFile (24573): at android.app.ActivityThread.access$800(ActivityThread.java:144)

E/MapFile (24573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)

E/MapFile (24573): at android.os.Handler.dispatchMessage(Handler.java:102)

E/MapFile (24573): at android.os.Looper.loop(Looper.java:135)

E/MapFile (24573): at android.app.ActivityThread.main(ActivityThread.java:5221)

E/MapFile (24573): at java.lang.reflect.Method.invoke(Native Method)

E/MapFile (24573): at java.lang.reflect.Method.invoke(Method.java:372)

E/MapFile (24573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

E/MapFile (24573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

D/AndroidRuntime(24573): Shutting down VM

E/AndroidRuntime(24573): FATAL EXCEPTION: main

E/AndroidRuntime(24573): Process: com.example.maps, PID: 24573

E/AndroidRuntime(24573): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maps/com.example.maps.FullscreenActivity}: org.mapsforge.map.reader.header.MapFileException: cannot read file: /storage/emulated/0/germany.map

E/AndroidRuntime(24573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)

E/AndroidRuntime(24573): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)

E/AndroidRuntime(24573): at android.app.ActivityThread.access$800(ActivityThread.java:144)

E/AndroidRuntime(24573): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)

E/AndroidRuntime(24573): at android.os.Handler.dispatchMessage(Handler.java:102)

E/AndroidRuntime(24573): at android.os.Looper.loop(Looper.java:135)

E/AndroidRuntime(24573): at android.app.ActivityThread.main(ActivityThread.java:5221)

E/AndroidRuntime(24573): at java.lang.reflect.Method.invoke(Native Method)

E/AndroidRuntime(24573): at java.lang.reflect.Method.invoke(Method.java:372)

E/AndroidRuntime(24573): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

E/AndroidRuntime(24573): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

E/AndroidRuntime(24573): Caused by: org.mapsforge.map.reader.header.MapFileException: cannot read file: /storage/emulated/0/germany.map

E/AndroidRuntime(24573): at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:259)

E/AndroidRuntime(24573): at com.example.maps.FullscreenActivity.onStart(FullscreenActivity.java:209)

E/AndroidRuntime(24573): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1220)

E/AndroidRuntime(24573): at android.app.Activity.performStart(Activity.java:5949)

E/AndroidRuntime(24573): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)

E/AndroidRuntime(24573): ... 10 more

W/ActivityManager(17752):   Force finishing activity com.example.maps/.FullscreenActivity


Note that 
  • permissions are fine on germany.map. Even tried chmod 777, no difference
  • I tried to access the sd card directly "/sdcard/germany.map", "/mnt/sdcard/germany.map", etc. No difference.
  • When I use the 
Looks like the file indeed exists but the map reader crashes when it starts reading the map? Using the latest version 0.5.1 of all jars.

What's happening? Any ideas?

thanks for your help


Emux

unread,
Mar 29, 2015, 9:25:44 AM3/29/15
to mapsfo...@googlegroups.com
Have you put the proper permission in manifest ?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

--
Emux
Cruiser - Atlas

Ludwig

unread,
Mar 29, 2015, 9:27:33 AM3/29/15
to mapsfo...@googlegroups.com
Also any corrupted (e.g. truncated) file will cause this problem.

Have you tried the file with the Samples app directly?



--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/5517FD53.7070005%40gmail.com.

For more options, visit https://groups.google.com/d/optout.

lele

unread,
Mar 29, 2015, 9:32:32 AM3/29/15
to mapsfo...@googlegroups.com
Thanks!
that fixed it. I would have thought Android would tell me explicitly about this but there was no mention of permissions in the error.

thanks again!

Shubham Verma

unread,
Nov 10, 2016, 7:35:59 AM11/10/16
to mapsforge-dev
hello i have same prob do u know how to resolve it

Emux

unread,
Nov 10, 2016, 7:56:36 AM11/10/16
to mapsfo...@googlegroups.com
He probably meant the missed permission in manifest.

--
Emux
Reply all
Reply to author
Forward
0 new messages