这适用于Android应用。第一个调用工作,而不是第二个调用,它们按顺序调用。没有错误。所有字符串都是应该的。第一个正确更新,但第二个不更新任何值。
///DOESN'T WORK
mDbHelper.updateValue(SaveSlot, item, value1,value2,"S");
public void updateValue(String saveslot, String item, String value1, String value2,String cat) {
ContentValues args = new ContentValues();
if (value1 !=null){
args.put(VALUE1, value1);
if (value2 !=null){
args.put(VALUE2, value2);
}}
else if (value2 !=null){
args.put(VALUE2, value2);
}
mDb.update(DATABASE_PUSHERS_TABLE, args, SAVE_SLOT + "=" + saveslot +" AND " + ITEM +" = "+item+" AND category = "+cat, null);
return ;
}
发现了一些错误消息......
INFO/dalvikvm(23920): Uncaught exception thrown by finalizer (will be discarded):
INFO/dalvikvm(23920): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@43dc3e90 on pushers that has not been deactivated or closed
INFO/dalvikvm(23920): at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
INFO/dalvikvm(23920): at dalvik.system.NativeStart.run(Native Method)
INFO/dalvikvm(23920): Uncaught exception thrown by finalizer (will be discarded):
INFO/dalvikvm(23920): Ljava/lang/IllegalStateException;: Finalizing cursor android.database.sqlite.SQLiteCursor@43da38c0 on pushers that has not been deactivated or closed
04-10 01:56:24.091: ERROR/Database(2983): Error updating value1=82 using UPDATE database SET value1=? WHERE save_slot=1 AND item = 98 AND category = S
答案 0 :(得分:0)
在变量周围加一个引号修复它..
mDb.update(DATABASE_PUSHERS_TABLE, args, SAVE_SLOT + " = '" + saveslot +"' AND " + ITEM +" = '"+item+"' AND category = '"+cat+"'", null);