MBTilesOsmDroidExample无法从Assets文件夹加载MBTiles文件

时间:2014-11-21 20:43:58

标签: android android-mapview osmdroid mbtiles

我正在编译MBTilesOsmDroidExample https://github.com/djcoin/MBTilesOsmdroidExample我收到了以下错误。

mbtile文件位于assest文件夹中。

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

以下是加载资产的代码。我没有更改除文件名之外的代码。

    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);

}

我的问题是否有人可以检查无法加载MBtiles文件资产文件夹的原因?

2 个答案:

答案 0 :(得分:0)

Environment.getExternalStorageDirectory(),“military-bene-and-tacan-routes.db”

此声明涉及sdcard而非资产。将.db文件放在SD卡上,它将运行

答案 1 :(得分:0)

OSMDroid仅从assets文件夹中执行原始图像。数据库必须位于/ sdcard / osmdroid或设备上的其他位置。为了加载切片,ITileSource名称必须与数据库中切片图层的名称相匹配。您可以编写采用现有的数据库加载器来删除该检查,这可能会简化您的工作