mapsforge, cannot read file: /storage/emulated/0/berlin.map

1,039 views
Skip to first unread message

Luis Navarro

unread,
Jul 6, 2016, 2:46:03 AM7/6/16
to mapsforge-dev
hi all,
im starting to develop an app with mapsforge, im trying the example https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Android-App.md, but when i run the app, show this error, the AndroidManifest have the correct permission <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

E/MapFile﹕ cannot read file: /storage/emulated/0/berlin.map
    org.mapsforge.map.reader.header.MapFileException: cannot read file: /storage/emulated/0/berlin.map

            at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:227)
            at org.mapsforge.map.reader.MapFile.<init>(MapFile.java:205)
            at com.example.luis.mapsforge.MainActivity.onCreate(MainActivity.java:53)
            at android.app.Activity.performCreate(Activity.java:6272)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
            at android.app.ActivityThread.access$900(ActivityThread.java:157)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5530)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)

Ludwig

unread,
Jul 6, 2016, 3:33:53 AM7/6/16
to mapsfo...@googlegroups.com
Most likely a corrupted map file or the file is not actually installed in the right directory. 


--
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 post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mapsforge-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/3f5c67f7-638f-45ce-ae3b-3799a646593e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Navarro

unread,
Jul 6, 2016, 3:41:15 AM7/6/16
to mapsforge-dev
the map file is correct, and is installed in the rigth directory, y test the file with a sample app

Emux

unread,
Jul 6, 2016, 3:45:15 AM7/6/16
to mapsfo...@googlegroups.com
Environment.getExternalStorageDirectory() usually refers to whatever the device manufacturer considered to be "external storage".
On some devices this is removable media, like an SD card.
On some devices this is a section of on-device flash, like /storage/emulated/0/.

You can try in code to create a File class with the full path and see it it actually exists, is readable etc.

BTW have you tested the Samples app (from downloads) to see if it works?

--
Emux

Ludwig

unread,
Jul 6, 2016, 3:47:00 AM7/6/16
to mapsfo...@googlegroups.com
IIRC the samples app wants a 'germany.map' file, you are trying to open 'berlin.map'. Maybe not the right name?

Luis Navarro

unread,
Jul 6, 2016, 2:56:59 PM7/6/16
to mapsforge-dev
i have the 2 mapfiles, named berlin.map and germany.map, i have tested the germany mapfile with a sample app and work right

Luis Navarro

unread,
Jul 6, 2016, 3:08:04 PM7/6/16
to mapsforge-dev
i have a LG k10Lte, i have the mapfile on /storage/emulated/0/. I have tested the sample app, work right with the mapfile

Emux

unread,
Jul 6, 2016, 3:11:24 PM7/6/16
to mapsfo...@googlegroups.com
You mean the Samples app from the Downloads I mentioned above, is working fine with the exact map file?
Note that Samples expects a germany.map file.

Then if your implementation does not work, there has to be something with it.

Can you post the relevant code to see what happens?

--
Emux

Luis Navarro

unread,
Jul 6, 2016, 3:31:41 PM7/6/16
to mapsforge-dev
it is the same sample code from https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Android-App.md, Android manifest have the correct permission

import java.io.File;

import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.android.util.AndroidUtil;
import org.mapsforge.map.android.view.MapView;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.layer.renderer.TileRendererLayer;
import org.mapsforge.map.datastore.MapDataStore;
import org.mapsforge.map.reader.MapFile;
import org.mapsforge.map.rendertheme.InternalRenderTheme;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;

public class MainActivity extends Activity {
// name of the map file in the external storage
private static final String MAP_FILE = "germany.map";

private MapView mapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

AndroidGraphicFactory.createInstance(this.getApplication());

this.mapView = new MapView(this);
setContentView(this.mapView);

this.mapView.setClickable(true);
this.mapView.getMapScaleBar().setVisible(true);
this.mapView.setBuiltInZoomControls(true);
//this.mapView.setZoomLevelMin((byte) 10);
//this.mapView.setZoomLevelMax((byte) 20);

// create a tile cache of suitable size
TileCache tileCache = AndroidUtil.createTileCache(this, "mapcache",
mapView.getModel().displayModel.getTileSize(), 1f,
this.mapView.getModel().frameBufferModel.getOverdrawFactor());

// tile renderer layer using internal render theme
MapDataStore mapDataStore = new MapFile(new File(Environment.getExternalStorageDirectory(), MAP_FILE));
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
this.mapView.getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);

// only once a layer is associated with a mapView the rendering starts
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);

this.mapView.setCenter(new LatLong(52.517037, 13.38886));
this.mapView.setZoomLevel((byte) 12);
}

@Override
protected void onDestroy() {
this.mapView.destroyAll();
AndroidGraphicFactory.clearResourceMemoryCache();
super.onDestroy();
}
}

Emux

unread,
Jul 6, 2016, 3:35:50 PM7/6/16
to mapsfo...@googlegroups.com
What you posted is the example code which works(?) on your device.

Your code which does not work?

--
Emux

Luis Navarro

unread,
Jul 6, 2016, 3:55:55 PM7/6/16
to mapsforge-dev
yes, i posted the example code, but this code doesnt work on my device

Emux

unread,
Jul 6, 2016, 3:57:49 PM7/6/16
to mapsfo...@googlegroups.com
Above you write that you tested the sample app and it works with the map file.

Which map file is that (link) and which exactly sample app works then?

--
Emux

Luis Navarro

unread,
Jul 6, 2016, 4:05:13 PM7/6/16
to mapsforge-dev
same link that provides the example http://download.mapsforge.org/maps/europe/germany.map
the app is the provided on downloads for developers, 

Release 0.6.1 (2016-06-11)

Ludwig

unread,
Jul 6, 2016, 4:08:06 PM7/6/16
to mapsfo...@googlegroups.com
Since your code complains about a berlin.map file not being found, this is clearly not the code you are trying to run.

--
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 post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mapsforge-dev.

Luis Navarro

unread,
Jul 6, 2016, 4:16:45 PM7/6/16
to mapsforge-dev
i have berlin.map and germany.map files on my device, y have tested with the 2 file name, the problem is not the map file or the map file name on code

Emux

unread,
Jul 6, 2016, 4:29:06 PM7/6/16
to mapsfo...@googlegroups.com
The checks in code for the provided map File can be seen here.

Those checks can be tested without Mapsforge in your app for the file:

new File(Environment.getExternalStorageDirectory(), MAP_FILE)

They should work, provided all permissions are right and you have correct access to device storage and file.

Also some devices lock the storage when connected via usb with the pc, examine that possibility too.

--
Emux

Luis Navarro

unread,
Jul 13, 2016, 11:12:27 PM7/13/16
to mapsforge-dev
i have solved the problem that cant read map file, i just goto my App permission and enable storage for the app (http://stackoverflow.com/questions/20631446/android-unable-to-open-content-file-storage-emulated-0).... but now i have other problem, my app run, but the map isnt show :(

Ludwig

unread,
Jul 13, 2016, 11:23:56 PM7/13/16
to mapsfo...@googlegroups.com
If you are on Android 6 using the Android 6+ SDKs you need to comply with the new permissioning system. Our samples app does this. 

With your map not showing I would recommend uninstalling and reinstalling, in case you have navigated out of the map area and have now nothing to show.



--
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 post to this group, send email to mapsfo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mapsforge-dev.

Emux

unread,
Jul 14, 2016, 2:03:28 AM7/14/16
to mapsfo...@googlegroups.com
On 14/07/2016 06:23 πμ, Ludwig wrote:
If you are on Android 6 using the Android 6+ SDKs you need to comply with the new permissioning system. Our samples app does this.

Additionally you can read the official docs about permissions.
https://developer.android.com/training/permissions/requesting.html

--
Emux

yogesh10446

unread,
Jul 15, 2016, 1:57:48 AM7/15/16
to mapsforge-dev
I think yo need to provide another permission for reading the files from the external storage as well

i.e. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Also if you are developing in a device with API >= 6.0 then i guess you need to check if  permission for the READ_EXTERNAL_STORAGE has been provided to your app.

Luis Navarro

unread,
Jul 20, 2016, 2:21:04 AM7/20/16
to mapsforge-dev
this is my logcat
W/DatabaseRenderer: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/caverock/androidsvg/SVG;

Emux

unread,
Jul 20, 2016, 2:37:39 AM7/20/16
to mapsfo...@googlegroups.com
See the library integration guide (link also on main page) for including properly Mapsforge in your app.

--
Emux

Luis Navarro

unread,
Jul 20, 2016, 5:37:46 AM7/20/16
to mapsforge-dev
Thanks so much for taking the time to respond, i solved the problem looking at integration guide, and enabling storage for the app on the device
Reply all
Reply to author
Forward
0 new messages