1

我尝试在 sqlite db 中插入一个条目,但这在某些设备上不起作用!插入适用于设备Huawei Nexus 6P (Android 6.0, API23)非常好,但不适用于设备Samsung SM-G930F (Android 6.0.1, API23)

你能帮我么!返回码始终为“res = -1”。这是我插入新注册的代码:

公共布尔插入注册(注册注册){

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put("phoneNumber", registration.getPhoneNumber());
    cv.put("serverPassword", registration.getServerPassword());
    cv.put("chatPassword", registration.getChatPassword());
    cv.put("username", registration.getUsername());
    cv.put("fileURL", registration.getFileURL());

    long res = 0;
    try
    {
        res = db.insert(TABLE_USER, null, cv);
    }
    catch(SQLException e)
    {
        // Sep 12, 2013 6:50:17 AM
        Log.e("Exception", "SQLException" + String.valueOf(e.getMessage()));
        e.printStackTrace();
    }

    if(res == -1)
        throw new RuntimeException("New registration can not be inserted into local db");
    db.close();
    return res >= 0;
}

调试器也不会赶上!不会返回任何警告或错误!

数据库看起来像这样:

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(DATABASE_CREATE_USER);
}

创建用户数据库字符串:

private static final String DATABASE_CREATE_USER = "创建表" + TABLE_USER + "(" + "id 整数主键自动增量," + "phoneNumber 文本不为空," + "serverPassword 文本不为空," + "chatPassword 文本不为空," + "fileURL text not null, " + "username text not null" + ");";

如果我调试这一行“res = db.insert(TABLE_USER, null, cv);”,我总是得到返回码“-1” 在设备“三星 SM-G930F”上。

先感谢您!

4

0 回答 0