I followed this for updating my database:Android SQLite: Update Statement
It works good, but when I run my application, it crashes by saying: unfortunately your app has stopped working.
Here is the output of my log:
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)I start calling the update function when onFinish() is executed:
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 = myemailThe db.UpdateUser functions is as follows:
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);}I try to update a row: total_usage, where column: email.
Updating some data is the most important part in my application.
Why the log gives this output:
while compiling: UPDATE users SET total_usage=? WHERE email =myemailI really hope someone can help me. Im trying more than 10 hours to solve this issue..
- are you sure, you typed the table name "users" correctly in both places? ensure that it doesn't contain any additional spaces. can you post the code snippet that uses to register user?Blue_Alien– Blue_Alien2014-12-11 15:17:53 +00:00CommentedDec 11, 2014 at 15:17
- I just solved the table name, thanks to CommonsWareSimple– Simple2014-12-11 15:20:23 +00:00CommentedDec 11, 2014 at 15:20
- how? let us know how you solved?Blue_Alien– Blue_Alien2014-12-11 15:21:41 +00:00CommentedDec 11, 2014 at 15:21
- In phpmyadmin, the table name was 'users'. In the Java file, it was defined at 'login'. Very but VERY dumb fault. But this happens when you try to solve issue hor hours long :\Simple– Simple2014-12-11 15:23:17 +00:00CommentedDec 11, 2014 at 15:23
1 Answer1
Change:
String strFilter = "email =" + email;to:
String strFilter = "email";and change:
db.update("users", args, strFilter, null);to:
db.update("users", args, strFilter, new String[] { email });2 Comments
Explore related questions
See similar questions with these tags.
