使用SQLiteAssetHelper从资产复制数据库

时间:2015-01-10 09:47:27

标签: android android-sqlite sqliteopenhelper

当我尝试使用Sqliteassethelper在android api level 8中打开我的数据库时,我的应用程序崩溃了这个错误cat log:

01-10 13:08:15.063      321-321/com.omidgraphic.naghshekhial E/SQLiteAssetHelper﹕ Couldn't open database.sqlite for writing (will try read-only):
    com.omidgraphic.naghshekhial.lib.SQLiteAssetHelper$SQLiteAssetException: Unable to write /data/data/com.omidgraphic.naghshekhial/databases/database.sqlite to data directory
            at android.content.res.AssetManager.readAsset(Native Method)
            at android.content.res.AssetManager.access$700(AssetManager.java:36)
            at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:571)
            at com.omidgraphic.naghshekhial.lib.Utils.writeExtractedFileToDisk(Utils.java:45)
            at com.omidgraphic.naghshekhial.lib.SQLiteAssetHelper.copyDatabaseFromAssets(SQLiteAssetHelper.java:459)
            at com.omidgraphic.naghshekhial.lib.SQLiteAssetHelper.createOrOpenDatabase(SQLiteAssetHelper.java:402)
            at com.omidgraphic.naghshekhial.lib.SQLiteAssetHelper.getWritableDatabase(SQLiteAssetHelper.java:176)
            at com.omidgraphic.naghshekhial.lib.SQLiteAssetHelper.getReadableDatabase(SQLiteAssetHelper.java:257)

有什么问题?

它的活动代码:

public class TestActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity);
        Data dt;
        dt= new Data(this);

    }
}

它的数据:

public class Data extends com.omidgraphic.naghshekhial.lib.SQLiteAssetHelper {

    private static final String DATABASE_NAME    = "database.sqlite";
    private static final int    DATABASE_VERSION = 1;
    private Context        context;
    private SQLiteDatabase mDb;

    public Data(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        this.context = context;
        db();
    }

不是关于数据库的大小? 4.34 MB (4,554,752 bytes)

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。使用解压缩版本的数据库工作。