我按照此更新了我的数据库:Android SQLite: Update Statement
它运行良好,但是当我运行我的应用程序时,它崩溃说:不幸的是你的应用程序已停止工作。
以下是我的日志输出:
android.database.sqlite.SQLiteException: no such table: users (code 1): , while compiling: UPDATE users SET total_usage=? WHERE email =myemail
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1688)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1636)
at com.example.userX.theneckoptimizer.library.DatabaseHandler.updateUser(DatabaseHandler.java:92)
at com.example.userX.theneckoptimizer.background$1.onFinish(background.java:101)
at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
执行onFinish()时,我开始调用更新函数:
public void onFinish() {
MyActivity.amountOfVibrations= MyActivity.amountOfVibrations+ 1;
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(500); //0.5 seconds of vibration
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
db.updateUser(RegisterActivity.email, "123456");
} // email = myemail
db.UpdateUser函数如下:
public void updateUser(String email, String total_usage) {
SQLiteDatabase db = this.getWritableDatabase();
String strFilter = "email =" + email;
ContentValues args = new ContentValues();
args.put(KEY_TOTAL_USAGE, total_usage);
db.update("users", args, strFilter, null);
}
我尝试更新一行:total_usage,其中column:email。
更新某些数据是我的应用程序中最重要的部分。
为什么日志会提供此输出:
while compiling: UPDATE users SET total_usage=? WHERE email =myemail
我真的希望有人可以帮助我。我尝试了10个多小时来解决这个问题..
答案 0 :(得分:0)
变化:
String strFilter = "email =" + email;
为:
String strFilter = "email";
并改变:
db.update("users", args, strFilter, null);
为:
db.update("users", args, strFilter, new String[] { email });