我的应用程序是通讯录,最后一切正常,但是当我“用户”添加新联系人时,我会强制关闭..但应用程序没有关闭,而是重新启动!当我检查联系人列表时,我发现我尝试添加的内容确实被添加了!!!logcat 说错误在这里:
return cursorToContact(cursor);
它是这个添加功能的一部分:
/** Add new Contact to Database. */
public Contact createContact(Contact contact) {
//Used to store data like : COLUMN_NAME , VALUE.
ContentValues values = new ContentValues();
values.put(MySQLiteHelper.COLUMN_FIRST_NAME, contact.getFirstName());
values.put(MySQLiteHelper.COLUMN_LAST_NAME, contact.getLastName());
//Insert new contact and get the id of it.
long insertId = database.insert(MySQLiteHelper.TABLE_NAME_FTS, null,
values);
//To show how to query (To get contact by it id).
Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME_FTS,
allColumns, MySQLiteHelper.COLUMN_ID + " = " + insertId,
null,
null, null, null);
//Move Cursor to the first row.
cursor.moveToFirst();
return cursorToContact(cursor);
}
那么为什么会发生这种情况>请帮助我注意我正在使用 sqlite fts3 数据库
cursorToContact :
/** Used to get Contact data from Cursor to Memo Object. */
private Contact cursorToContact(Cursor cursor) {
Contact contact = new Contact();
contact.setId(cursor.getLong(0));
contact.setFirstName(cursor.getString(1));
contact.setLastName(cursor.getString(2));
return contact;
}