SQLiteReadOnlyDatabaseException: attempt to write a readonly database

左心房为你撑大大i 提交于 2019-12-02 02:22:26

You need to make a writable database if you want to insert values in database need to add these lines in constructor

DBHelper helper = new DBHelper (mCtx);
                this.db = helper.getWritableDatabase();

      public Restaurant(Context c)
{   
    myContext = c;

                DBHelper helper = new DBHelper (mCtx);
            this.db = helper.getWritableDatabase();
}           
Kuffs

You cannot write to a database that is stored in your assets folder as that is part of your apk and cannot be changed.

When your app runs you should check for the existence of a database (in the normal databases folder) and if it does not exist, copy the database from your assets folder and use that instead.

See these links for more info.

http://www.devx.com/wireless/Article/40842

Ship an application with a database

Letter tran
public void openDataBase() throws SQLException{

    //Open the database
    String myPath = DB_PATH + DATABASE_NAME;
    ourDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

}

You must change SQLiteDatabase.OPEN_READONLY to SQLiteDatabase.OPEN_READWRITE, because OPEN_READONLY only allows to read not write.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!