I am compiling MBTilesOsmDroidExample https://github.com/djcoin/MBTilesOsmdroidExample I am getting following error.
the mbtile file is in the assest folder.
11-21 12:29:29.693: E/Database(330): sqlite3_open_v2("/mnt/sdcard/military-bene-and-tacan-routes.db", &handle, 1, NULL) failed
11-21 12:29:29.693: D/AndroidRuntime(330): Shutting down VM
11-21 12:29:29.693: W/dalvikvm(330): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-21 12:29:29.723: E/AndroidRuntime(330): FATAL EXCEPTION: main
11-21 12:29:29.723: E/AndroidRuntime(330): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.tilespitter.mapboxtiles/org.tilespitter.mapboxtiles.MBTilesOsmdroidExample}: android.database.sqlite.SQLiteException: unable to open database file
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.os.Looper.loop(Looper.java:123)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-21 12:29:29.723: E/AndroidRuntime(330): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 12:29:29.723: E/AndroidRuntime(330): at java.lang.reflect.Method.invoke(Method.java:507)
11-21 12:29:29.723: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-21 12:29:29.723: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-21 12:29:29.723: E/AndroidRuntime(330): at dalvik.system.NativeStart.main(Native Method)
11-21 12:29:29.723: E/AndroidRuntime(330): Caused by: android.database.sqlite.SQLiteException: unable to open database file
11-21 12:29:29.723: E/AndroidRuntime(330): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1849)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
11-21 12:29:29.723: E/AndroidRuntime(330): at org.osmdroid.tileprovider.modules.MBTilesFileArchive.getDatabaseFileArchive(MBTilesFileArchive.java:43)
11-21 12:29:29.723: E/AndroidRuntime(330): at org.tilespitter.mapboxtiles.MBTilesOsmdroidExample.mapBeginConfig(MBTilesOsmdroidExample.java:55)
11-21 12:29:29.723: E/AndroidRuntime(330): at org.tilespitter.mapboxtiles.MBTilesOsmdroidExample.onCreate(MBTilesOsmdroidExample.java:43)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-21 12:29:29.723: E/AndroidRuntime(330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-21 12:29:29.723: E/AndroidRuntime(330): ... 11 more
Here is the code that load assets. I did not change the code other than the name of file.
private void mapBeginConfig(){
mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this);
File f = new File(Environment.getExternalStorageDirectory(), "military-bene-and-tacan-routes.db"); //change from map.mbtiles
IArchiveFile[] files = { MBTilesFileArchive.getDatabaseFileArchive(f) };
MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(simpleReceiver, MBTILESRENDER, files);
mProvider = new MapTileProviderArray(MBTILESRENDER, null,
new MapTileModuleProviderBase[]{ moduleProvider }
);
this.mOsmv = new MapView(this, 256, mResourceProxy, mProvider);
}
My question if can someone check why unable to load the MBtiles files assets folder?
Environment.getExternalStorageDirectory(), "military-bene-and-tacan-routes.db"
This statement refers to sdcard not assets. Place your .db file on sdcard and it will run