SQLiteException尝试重新打开已关闭的对象:SQLiteDatabase

时间:2015-08-10 20:30:34

标签: android sqlite

我正在尝试添加更新方法来更新用户信息。 这是我的更新方法:

//updating sqlite database with the group name
    public void updateUserGroup(String groupName) {

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_GROUP, groupName);
        HashMap<String, String> user = getUserDetails();
        String userID = user.get("uid");

        System.out.println("User id is: " + userID);
        db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=\"" + userID + "\"", null);
    }

这是错误:

 java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/cindyliu96.test/databases/android_api
            at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
            at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1545)
            at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1522)

1 个答案:

答案 0 :(得分:0)

如何打开数据库连接

db.open();

当您完成交易或查询时

db.close();