在SQlite類中的put方法出現編譯錯誤。
put下劃線得到的信息: "change type of "KEY_CHECKBOX_STATUS" to String"
contentValues.put(KEY_CHECKBOX_STATUS, checkBoxStatus);
需要在put方法中使用整數型,怎麼辦?
數據庫變量:
public static final String MYDATABASE_NAME = "my_database";
public static final String MYDATABASE_TABLE = "my_table";
public static final int MYDATABASE_VERSION = 1;
public static final int KEY_CHECKBOX_STATUS = 0;
public static final String KEY_CHECKBOX_LABEL = "Example Label";
//create table MY_DATABASE (ID integer primary key, Content text not null);
private static final String SCRIPT_CREATE_DATABASE =
"CREATE_TABLE IF NOT EXISTS " + MYDATABASE_TABLE + " (" + "ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
+ KEY_CHECKBOX_STATUS + " BIT, " + KEY_CHECKBOX_LABEL + " TEXT NOT NULL);";
insert方法:
public void insert(Integer checkBoxStatus){
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_CHECKBOX_STATUS, checkBoxStatus); // <-- compiler error
sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
}
在put方法中第一個參數應該是string,checkBoxStatus 可以是整型,只要修改
public static final int KEY_CHECKBOX_STATUS = 0;
用這句代碼代替:
public static final String KEY_CHECKBOX_STATUS = "check_box_status;