Mapsforge file does not exist

254 views
Skip to first unread message

long huynh

unread,
Mar 4, 2016, 6:45:37 AM3/4/16
to mapsforge-dev
Hey.

I'm kinda new to this, I have been using mapsforge SDK for a few months now. I have a problem that is keeping me from moving further with my prosject and I cant seems to solve it. I have tried to render my own .map file and it works. In the past few days I have been trying to render a new .map file, but it seems it doesnt render at all. 

1. I get "org.mapsforge.map.reader.header.MapFileException: file does not exist: /storage/emulated/0/testing.map" when I change the mapfile name to something else than germany.map. 

2. I keep getting the old .map file up when i rename the new .map file to germany.map and try to render it. I have tried to clear catche and everything. 

Here are some of my codes:


    public XmlRenderTheme getRenderTheme() {
try {
return new AssetsRenderTheme(this.getActivity(), getRenderThemePrefix(), getRenderThemeFile(), this);
} catch (IOException e) {
Log.e(SamplesApplication.TAG, "Render theme failure " + e.toString());
}
return null;
}

public String getRenderThemePrefix() {
return "";
}

/** Henter rendertheme fila */
public String getRenderThemeFile() {
return "renderthemes/rendertheme-v4.xml";
}
private void createLayer() {
this.tileRendererLayer = AndroidUtil.createTileRendererLayer(tileCache,
mapView.getModel().mapViewPosition, getMapFile(), getRenderTheme(), false, true);
tileRendererLayer.setXmlRenderTheme(getRenderTheme());
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);
}
private void creatTileCache() {
LayerManager layerManager = this.mapView.getLayerManager();
Layers layers = layerManager.getLayers();

MapViewPosition mapViewPosition = this.mapView.getModel().mapViewPosition;
mapViewPosition.setZoomLevel((byte) 16);

tileCache = AndroidUtil.createTileCache(this.getActivity(),
"fragments",
this.mapView.getModel().displayModel.getTileSize(), 1.0f,
1.5);
layers.add(AndroidUtil.createTileRendererLayer(this.tileCache,
mapViewPosition, getMapFile(),
getRenderTheme(), false, true));
}
public MapFile getMapFile() {
MapFile mapFile = new MapFile(new File(Environment.getExternalStorageDirectory(),
this.getMapFileName()));
return mapFile;
}
protected String getMapFileName() {
return "testing.map";
}



Emux

unread,
Mar 4, 2016, 6:54:11 AM3/4/16
to mapsfo...@googlegroups.com
The above code is a bit confused, as I see addition of tileRendererLayer two times.

Can you try our simple example here in getting started guide?

--
Emux

long huynh

unread,
Mar 4, 2016, 7:03:01 AM3/4/16
to mapsforge-dev
Yes I have been following that. Just ignore "tileRendererLayer.setXmlRenderTheme(getRenderTheme());" its not suppose to be there. My other problem is still not finding .map when i rename it to anything else than germany.map. 

Emux

unread,
Mar 4, 2016, 7:09:09 AM3/4/16
to mapsfo...@googlegroups.com
That line has nothing to do with the map file, it's about the render theme.

In your code you add two times the layer, in createLayer and in creatTileCache (which should be used only for cache).

I suggest to copy / paste the linked example (instead of Samples app) and see how it goes.

--
Emux

long huynh

unread,
Mar 4, 2016, 7:27:37 AM3/4/16
to mapsforge-dev
Thanks for reply. I know that line has nothing to do with the map file. I'm talking about

public MapFile getMapFile() {
MapFile mapFile = new MapFile(new File(Environment.getExternalStorageDirectory(),
this.getMapFileName()));
return mapFile;
}
protected String getMapFileName() {
return "testing.map";
}

i get the error "org.mapsforge.map.reader.header.MapFileException: file does not exist: /storage/emulated/0/testing.map" when I change the mapfile name to something else than germany.map. I'm wondering why this is happening, why i'm stuck to use the name germany?

Emux

unread,
Mar 4, 2016, 7:36:19 AM3/4/16
to mapsfo...@googlegroups.com
You have created another map file and put it in the device storage?

--
Emux

long huynh

unread,
Mar 4, 2016, 7:39:13 AM3/4/16
to mapsforge-dev
Yes, ofcourse, but the error disappear when i rename the file back to germany.map. It seems the code does not accept anything than germany.map.

Emux

unread,
Mar 4, 2016, 7:40:52 AM3/4/16
to mapsfo...@googlegroups.com
It seems something is wrong in the implementation then.

Again create a simple activity from the Getting Started example, it's the easiest way to start.

--
Emux

long huynh

unread,
Mar 4, 2016, 7:51:41 AM3/4/16
to mapsforge-dev
I followed your advice and copy paste the entire code, the only thing I changed was the 
private static final String MAPFILE = "testing.map";

ERRORS:

03-04 13:50:07.170 6530-6530/? I/art: Late-enabling -Xcheck:jni
03-04 13:50:07.300 6530-6530/org.mapsforge.applications.android.samples I/GMPM: App measurement is starting up, version: 8487
03-04 13:50:07.300 6530-6530/org.mapsforge.applications.android.samples I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
03-04 13:50:07.340 6530-6530/org.mapsforge.applications.android.samples E/Mapsforge Samples: Device scale factor 3.0
03-04 13:50:07.340 6530-6530/org.mapsforge.applications.android.samples E/Mapsforge Samples: User ScaleFactor 1.0
03-04 13:50:07.510 6530-6530/org.mapsforge.applications.android.samples I/AndroidUtil: TILECACHE INMEMORY SIZE: 16
03-04 13:50:07.510 6530-6530/org.mapsforge.applications.android.samples W/ContextImpl: Failed to ensure directory: /storage/sdcard1/Android/data/org.mapsforge.applications.android.samples/cache
03-04 13:50:07.520 6530-6530/org.mapsforge.applications.android.samples I/AndroidUtil: TILECACHE FILE SIZE: 848
03-04 13:50:07.520 6530-6530/org.mapsforge.applications.android.samples E/MapFile: file does not exist: /storage/emulated/0/testing.map
                                                                                   org.mapsforge.map.reader.header.MapFileException: file does not exist: /storage/emulated/0/testing.map
                                                                                       at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:223)
                                                                                       at org.mapsforge.applications.android.samples.Samples.onStart(Samples.java:89)
                                                                                       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1224)
                                                                                       at android.app.Activity.performStart(Activity.java:6032)
                                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
                                                                                       at android.app.ActivityThread.access$1200(ActivityThread.java:152)
                                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5539)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
03-04 13:50:07.520 6530-6530/org.mapsforge.applications.android.samples E/MapFile: Attempt to invoke virtual method 'void org.mapsforge.map.reader.IndexCache.destroy()' on a null object reference
                                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'void org.mapsforge.map.reader.IndexCache.destroy()' on a null object reference
                                                                                       at org.mapsforge.map.reader.MapFile.closeFile(MapFile.java:274)
                                                                                       at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:243)
                                                                                       at org.mapsforge.applications.android.samples.Samples.onStart(Samples.java:89)
                                                                                       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1224)
                                                                                       at android.app.Activity.performStart(Activity.java:6032)
                                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
                                                                                       at android.app.ActivityThread.access$1200(ActivityThread.java:152)
                                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5539)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
03-04 13:50:07.520 6530-6530/org.mapsforge.applications.android.samples E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                          Process: org.mapsforge.applications.android.samples, PID: 6530
                                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{org.mapsforge.applications.android.samples/org.mapsforge.applications.android.samples.Samples}: org.mapsforge.map.reader.header.MapFileException: file does not exist: /storage/emulated/0/testing.map
                                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2406)
                                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466)
                                                                                              at android.app.ActivityThread.access$1200(ActivityThread.java:152)
                                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341)
                                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                              at android.os.Looper.loop(Looper.java:135)
                                                                                              at android.app.ActivityThread.main(ActivityThread.java:5539)
                                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                                                                                           Caused by: org.mapsforge.map.reader.header.MapFileException: file does not exist: /storage/emulated/0/testing.map
                                                                                              at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:244)
                                                                                              at org.mapsforge.applications.android.samples.Samples.onStart(Samples.java:89)
                                                                                              at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1224)
                                                                                              at android.app.Activity.performStart(Activity.java:6032)
                                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466) 
                                                                                              at android.app.ActivityThread.access$1200(ActivityThread.java:152) 
                                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) 
                                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                              at android.os.Looper.loop(Looper.java:135) 
                                                                                              at android.app.ActivityThread.main(ActivityThread.java:5539) 
                                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                                              at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
03-04 13:50:07.540 6530-6530/org.mapsforge.applications.android.samples I/Process: Sending signal. PID: 6530 SIG: 9

Emux

unread,
Mar 4, 2016, 7:55:05 AM3/4/16
to mapsfo...@googlegroups.com
Have you put the needed external storage permissions in manifest?
(I suppose you did if it reads fine the germany.map)

Is the testing.map a valid map file?

--
Emux

long huynh

unread,
Mar 4, 2016, 7:58:20 AM3/4/16
to mapsforge-dev
Yes, it only render when i change it to germany.map and nothing else. It seems like its hardcoded to use the name germany only....

Emux

unread,
Mar 4, 2016, 8:00:08 AM3/4/16
to mapsfo...@googlegroups.com
I see in log "Failed to ensure directory: /storage/sdcard1/Android/data/org.mapsforge.applications.android.samples/cache".

Where did you put the germany.map and where the testing.map?
Does your device has sdcard?

--
Emux

long huynh

unread,
Mar 4, 2016, 8:17:40 AM3/4/16
to mapsforge-dev
I only have one .map file that i rename back and forth. I have it in the SD card in the main level along side with the other folders. Music, pictures etc.

Emux

unread,
Mar 4, 2016, 8:28:00 AM3/4/16
to mapsfo...@googlegroups.com
If the device has an sd-card the Environment.getExternalStorageDirectory() will give the path to wherever the manufacturer has set the external storage to be.

Also it can be inaccessible if it's mounted at the same time by the pc.

To understand, if the map file has the name "germany.map" (in storage and code) all work?

And then if (with closed the app) you change the name of the map file on the storage and reinstall the app (with also changed the filename in the code) there is a problem?

--
Emux

long huynh

unread,
Mar 4, 2016, 8:41:25 AM3/4/16
to mapsforge-dev
Yes the problem occures when i change the filename and rerun the app. But it works fine when I run it with the germany.map name. Im kinda stuck using the name germany. 

Emux

unread,
Mar 4, 2016, 8:43:02 AM3/4/16
to mapsfo...@googlegroups.com
- You rename the file in device storage
- And change the name in the code and reinstall the app ?

--
Emux

long huynh

unread,
Mar 4, 2016, 8:50:21 AM3/4/16
to mapsforge-dev
Yes, as you can see i changed the private static final String MAPFILE = "testing.map";
And I also changed the .map file in my device to that name too.

Ludwig

unread,
Mar 4, 2016, 8:58:14 AM3/4/16
to mapsfo...@googlegroups.com
Most likely you are actually picking up a germany.map file from a different directory than you think you are accessing. ...


--
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/10f8e229-81e9-4156-872a-c96986a89103%40googlegroups.com.

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

long huynh

unread,
Mar 4, 2016, 9:09:03 AM3/4/16
to mapsforge-dev
I think you are right. I renamed the .map in my phone to testing. But I didnt not rename the variable MAPFILE in my code. The app did not crash. It seems like its not using the .map file in my sd card... but a germany.map file somewhere... Is it possible to force it to use a a file in a specific directory?

Emux

unread,
Mar 4, 2016, 9:14:14 AM3/4/16
to mapsfo...@googlegroups.com
See the Android docs about the file system:
http://developer.android.com/training/basics/data-storage/files.html

You need to place the map in a place and provide the location in the code.

--
Emux

long huynh

unread,
Mar 4, 2016, 9:15:44 AM3/4/16
to mapsforge-dev
Thanks for the trouble.
Message has been deleted

sagi...@gmail.com

unread,
Jan 9, 2019, 8:46:05 AM1/9/19
to mapsforge-dev
I have downloaded map file from this link "http://download.mapsforge.org/maps/v5/asia/india.map". Is this a valid map sir?
I am playing with GettingStarted.java file and gettting following error.



01-09 19:14:42.000 17572-17572/com.example.sagitsri.somap I/AndroidUtil: TILECACHE INMEMORY SIZE: 16
01-09 19:14:42.006 17572-17572/com.example.sagitsri.somap I/AndroidUtil: TILECACHE FILE SIZE: 2000
01-09 19:14:42.022 17572-17572/com.example.sagitsri.somap I/Path: /storage/emulated/0/india.map
01-09 19:14:42.048 17572-17572/com.example.sagitsri.somap W/System.err: org.mapsforge.map.reader.header.MapFileException: unsupported file version: 5
01-09 19:14:42.049 17572-17572/com.example.sagitsri.somap W/System.err:     at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:245)
01-09 19:14:42.049 17572-17572/com.example.sagitsri.somap W/System.err:     at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:207)
01-09 19:14:42.049 17572-17572/com.example.sagitsri.somap W/System.err:     at com.example.sagitsri.somap.GettingStarted.onCreate(GettingStarted.java:62)
01-09 19:14:42.049 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.Activity.performCreate(Activity.java:7030)
01-09 19:14:42.049 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.Activity.performCreate(Activity.java:7021)
01-09 19:14:42.050 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
01-09 19:14:42.050 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2759)
01-09 19:14:42.050 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2884)
01-09 19:14:42.050 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.ActivityThread.-wrap11(Unknown Source:0)
01-09 19:14:42.051 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1614)
01-09 19:14:42.051 17572-17572/com.example.sagitsri.somap W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
01-09 19:14:42.051 17572-17572/com.example.sagitsri.somap W/System.err:     at android.os.Looper.loop(Looper.java:164)
01-09 19:14:42.051 17572-17572/com.example.sagitsri.somap W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6524)
01-09 19:14:42.051 17572-17572/com.example.sagitsri.somap W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
01-09 19:14:42.052 17572-17572/com.example.sagitsri.somap W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
01-09 19:14:42.052 17572-17572/com.example.sagitsri.somap W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)

Emux

unread,
Jan 9, 2019, 8:49:21 AM1/9/19
to mapsfo...@googlegroups.com
Do you use the latest Mapsforge (to be compatible with maps v5) ?

Or can download previous version of maps from same server.

--
Emux

srinivas sagit

unread,
Jan 10, 2019, 4:13:39 AM1/10/19
to mapsfo...@googlegroups.com
Thank you for quick response sir!
I am using Mapsforge 0.8.0 version. I try to download and use lower versions sir!


--
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.

Emux

unread,
Jan 10, 2019, 4:15:43 AM1/10/19
to mapsfo...@googlegroups.com
Or better use the latest Mapsforge with all improvements and fixes.

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