有人可以帮我指出错误是什么吗?我放了这个后,我的应用程序崩溃了。
public String getLastString() {
String selectQuery = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToLast();
LastString = cursor.getString(0);
cursor.close();
db.close();
return LastString;
}
public void deleteLastMessage() {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME,null ,new String[] { getLastString() });
db.close();
}
答案 0 :(得分:0)
试试这个
public void deleteLastMessage() {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME,"COLNAME = ?",new String[] { getLastString() });
db.close();
}
答案 1 :(得分:0)
缺少Where子句
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME,"COLLUMNNAME = '"+ getLastString()+"'",null});
db.close();
答案 2 :(得分:0)
我已经解决了这个问题,谢谢所有
// Deleting single contact
public void deleteLastMessage(SubliminalMsg a) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME, KEY_MSG + " = ?",
new String[] { String.valueOf(a.get_message()) });
db.close();
}
public String getLastString() {
String selectQuery = "SELECT * FROM " + TABLE_NAME;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToLast();
LastString = cursor.getString(0);
cursor.close();
db.close();
return LastString;
}
活动
public void delete(View v) {
LastMessage = new SubliminalMsg(db.getLastString());
db.deleteLastMessage(LastMessage);
displayText();
}