-1

I'm a student and new to Android and Sqlite database.

I've been trying to update the data in my sqLite Database I tried many methods to update the data and after a lot of research it come up with an error in the Update class which is the id. Error:(92, 35) error: cannot find symbol variable id error message

Please check my codes to let me know where my mistakes is. THANK YOU.

DatabaseHelper class:

 public boolean updateData(long id, String new_question, String new_ans1, String new_ans2, String new_ans3, String new_ans4, SQLiteDatabase sqLiteDatabase )
    {
    ContentValues contentValues = new ContentValues();

        contentValues.put(AdminContact.Question.COLUMN_QUESTION, new_question);
        contentValues.put(AdminContact.Question.COLUMN_ANSWER1, new_ans1);
        contentValues.put(AdminContact.Question.COLUMN_ANSWER2, new_ans2);
        contentValues.put(AdminContact.Question.COLUMN_ANSWER3, new_ans3);
        contentValues.put(AdminContact.Question.COLUMN_ANSWER4, new_ans4);

       // String selection = AdminContact.Question.TABLE_QUIZ + " LIKE ?";
        //String[] selection_arg = {new_question};
       sqLiteDatabase.update(AdminContact.Question.TABLE_QUIZ, contentValues, AdminContact.Question.ID + "=" + id, null);
        return i > 0;

    }

This is my Create Table:

 private static final String CREATE_QUERY = "CREATE TABLE "+ AdminContact.Question.TABLE_QUIZ+"("+ AdminContact.Question.ID+" INTEGER PRIMARY KEY NOT NULL,"+ AdminContact.Question.COLUMN_QUESTION+" TEXT NOT NULL,"+
            AdminContact.Question.COLUMN_ANSWER1+" TEXT NOT NULL,"+ AdminContact.Question.COLUMN_ANSWER2+" TEXT NOT NULL,"+ AdminContact.Question.COLUMN_ANSWER3+" TEXT NOT NULL,"+ AdminContact.Question.COLUMN_ANSWER4+" TEXT NOT NULL);";


And my Update class:

 public void updateData(View view)
    {
    helper = new DatabaseHelper(this);
        sqLiteDatabase = helper.getWritableDatabase();

        String question, ans1, ans2, ans3, ans4;

        question = New_Question.getText().toString();
        ans1 = New_Ans1.getText().toString();
        ans2 = New_Ans2.getText().toString();
        ans3 = New_Ans3.getText().toString();
        ans4 = New_Ans4.getText().toString();
        helper.updateData(id,question,ans1,ans2,ans3,ans4,sqLiteDatabase);
        Toast.makeText(getApplicationContext()," Successfully Updated", Toast.LENGTH_LONG).show();
        finish();

    }
Jun'z
  • 67
  • 10
  • Could you include the error log in your question please? – PPartisan Jan 06 '16 at 22:14
  • Error:(92, 35) error: cannot find symbol variable id, thank you sir – Jun'z Jan 06 '16 at 22:17
  • Well, at a guess it's because `updateData(View view)` doesn't include `id` in its arguments...unlike your other `updateData()` method that returns a `boolean`. Editing your question to include your error log and specifying which line in your code caused the error will be a big help. **Edit** In addition, `int i = helper.updateData()` doesn't make sense, as this method returns a `boolean`, not an `int`. – PPartisan Jan 06 '16 at 22:19
  • Please can you help me fix the error through codes sir? – Jun'z Jan 06 '16 at 22:41

1 Answers1

0

In the updateData(View view) method in the Update class, the following line references id, but it is not defined in this class: helper.updateData(id,question,ans1,ans2,ans3,ans4,sqLiteDatabase);

Kingo
  • 440
  • 2
  • 9