jeudi 28 avril 2016

near "?": syntax error (code 1): , while compiling: UPDATE and DELETE

//deleting query

public void deleteFromQuestion(int questionId) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL("delete from Questions where question_id =" + questionId);

}
//updating query
public void updateQuestion(String question, String answerOne, String answerTwo, String answerThree, String answerFour, String correctAnswer, int id) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues contentValues = new ContentValues();

    contentValues.put("question", question);
    contentValues.put("answer_one", answerOne);
    contentValues.put("answer_two", answerTwo);
    contentValues.put("answer_three", answerThree);
    contentValues.put("answer_four", answerFour);
    contentValues.put("correct_answer", correctAnswer);
    db.update("Questions", contentValues,"question_id ?", new String[]{String.valueOf(id)});

}

and this is the code of update and delete

//update button code
 updateBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            questionStr = String.valueOf(questionET.getText());
            answerOneStr = String.valueOf(ansOneET.getText());
            answerTwoStr = String.valueOf(ansTwoET.getText());
            answerThreeStr = String.valueOf(ansThreeET.getText());
            answerFourStr = String.valueOf(ansFourET.getText());
            correctAnswerStr = String.valueOf(correctAnsET.getText());
            if (questionStr == null || answerOneStr == null || answerTwoStr == null || correctAnswerStr == null) {
                Toast.makeText(getApplicationContext(), "Please Fill Fields ", Toast.LENGTH_SHORT).show();
            } else {
                questionManagerObject.updateQuestion(questionStr, answerOneStr, answerTwoStr, answerThreeStr, answerFourStr, correctAnswerStr, questionId);
                Toast.makeText(getApplicationContext(), "Question Updated ", Toast.LENGTH_SHORT).show();
            }
        }
    });

//delete button code
    deleteBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            questionManagerObject.deleteFromQuestion(questionId);
            Toast.makeText(getApplicationContext(), "Question deleted ", Toast.LENGTH_SHORT).show();

        }
    });

it is supposed to delete with the question id and update with it also these are buttons when click it , it will delete or update ...... this error, what's wrong with this code??

Aucun commentaire:

Enregistrer un commentaire