我正在尝试在我的 sqlite 数据库中插入日期选择器和时间选择器中的值。我已将日期和时间存储在对象变量中,然后在我的 DBhandler 类中调用一个方法以通过 contentvalue 对象插入它们。
现在我在这里失败的是实际的插入和数据类型。
我在“timeApp”和“dateApp”的以下代码中遇到错误我将这些变量作为 DATE 和 TIME 变量传递给 createAppointmentEntry 方法:
错误信息:
The method put(String, String) in the type ContentValues is not applicable for the arguments (String, Time)
处理发生的错误:
public void createAppointmentEntry(String nameApp, String typeApp, Time timeApp, Date dateApp ,String commentApp, Boolean onOrOff) {
ContentValues cv = new ContentValues();
cv.put(KEY_NAMEAPP, nameApp);
cv.put(KEY_TYPEAPP, typeApp);
//ERROR on the following two 'puts'
cv.put(KEY_TIMEAPP, timeApp);
cv.put(KEY_DATEAPP, dateApp);
cv.put(KEY_COMMENTAPP, commentApp);
cv.put(KEY_ALARM, onOrOff);
ourDatabase.insert(DATABASE_TABLE, null, cv);
这是我的数据库列:
public static final String KEY_ROWAPPID = "_appid";
public static final String KEY_NAMEAPP = "app_name";
public static final String KEY_TYPEAPP = "app_type";
public static final String KEY_TIMEAPP = "app_time";
public static final String KEY_DATEAPP = "app_date";
public static final String KEY_COMMENTAPP = "app_comments";
public static final String KEY_ALARM = "app_alarm";
我的 onCreate 方法:
db.execSQL("CREATE TABLE " + DATABASE_TABLEAPP + " (" +
KEY_ROWAPPID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAMEAPP + " TEXT NOT NULL, " +
KEY_TYPEAPP + " TEXT NOT NULL, " +
KEY_TIMEAPP + " TEXT NOT NULL, " +
KEY_DATEAPP + " TEXT NOT NULL, " +
KEY_COMMENTAPP + " TEXT NOT NULL, " +
KEY_ALARM + "BOOLEAN NOT NULL);"
);
下面是我设置时间和日期对象变量的方法:
Date setDate = new Date(dobYear - 1900, dobMonth, dobDate);
Time timeToSet = new Time();
timeToSet.set(0, dobMinute, dobHour);