简体   繁体   English

SQLiteAssetHelper 中缺少数据库错误

[英]Missing databases error in SQLiteAssetHelper

I have a database in assets/databases and also have a class to read data from my database but when open database i got Missing databases error我在资产/数据库中有一个数据库,还有一个 class 可以从我的数据库中读取数据,但是当打开数据库时,我得到了缺少数据库错误

Note: i have myDb.zip in assets/databases注意:我在资产/数据库中有 myDb.zip

this is my Class to open database:这是我的 Class 打开数据库:

public class DB_helper extends SQLiteAssetHelper {
    private static final String DATABASE_NAME = "myDb.db";
    private static final int DATABASE_VERSION = 1;

    public DB_helper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    }

}

and in this line i call it:在这一行中,我称之为:

 SQLiteDatabase mydb = new DB_helper(appContext).getWritableDatabase();

i got this error:我收到了这个错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ir.dpsoft.saman, PID: 10620
    com.readystatesoftware.sqliteasset.SQLiteAssetHelper$SQLiteAssetException: Missing databases/myDb.db file (or .zip, .gz archive) in assets, or target folder not writable

SQLiteAssetHelper just appends .zip or .gz suffixes to the base name, not replacing anything in the file path. SQLiteAssetHelper只是将.zip.gz后缀附加到基本名称,而不是替换文件路径中的任何内容。

You can fix this either in the asset name or in code.您可以在资产名称或代码中解决此问题。 To fix the asset, ship your database as myDb.db.zip , not myDb.zip .要修复资产,请将数据库作为myDb.db.zip而非myDb.zip Or to fix the code, pass the database name as myDb and not myDb.db .或者要修复代码,请将数据库名称作为myDb而不是myDb.db

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM