0

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 = myemail

The 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 =myemail

I really hope someone can help me. Im trying more than 10 hours to solve this issue..

askedDec 11, 2014 at 13:49
Simple's user avatar
4
  • 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?CommentedDec 11, 2014 at 15:17
  • I just solved the table name, thanks to CommonsWareCommentedDec 11, 2014 at 15:20
  • how? let us know how you solved?CommentedDec 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 :\CommentedDec 11, 2014 at 15:23

1 Answer1

0

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 });
answeredDec 11, 2014 at 14:57
CommonsWare's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

the log says: android.database.sqlite.SQLiteException: no such table: users (code 1): , while compiling: UPDATE users SET total_usage=? WHERE email This is a general issue, I checked nearly all questions, but still not solved. Thanks anyway for your time sir
Your previous answer was right. In the Java file, name was login and in phpmyadmin, the name was users. You were right by saying "how do u look to the name of the table". Thanks for your time

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.