0

I'm developing Quiz app using SQLite in Android studio. I have methods to check the answer while button is pressed by the user, but those methods don't work without throwing any runtime exceptions. When I debug the the code I get the following message:"Source code does not match the bytecode" and so I can't debug my methods and find my code. Does anyone know what is the problem with the code?

private void startQuiz() {

    Collections.shuffle(questionList); // shuffle the questions form the database that are stored in QuestionList
    showQuestions();

    nextbutton.setOnClickListener(view -> {
        if(!answered){
            if(option1.isChecked() || option2.isChecked() || option3.isChecked() || option4.isChecked())
                QuizOperations();
        }else{
            Toast.makeText(QuizActivity.this,"Please Select Option", Toast.LENGTH_SHORT).show();
        }
    });
}

private void QuizOperations(){

    answered = true; // when the quiz is already answered Set bool to true
    RadioButton rbSelected = findViewById(rbGroup.getCheckedRadioButtonId());
    int answerNr = rbGroup.indexOfChild(rbSelected)+1;
    checkSolution(answerNr,rbSelected);// method checks if the answer that is selected by the user corresponds to the answer in the database
}

private void checkSolution(int answerNr, RadioButton rbSelected) {

    switch (currentQuestions.getCorrectAns()){
        case 1:
            if(currentQuestions.getCorrectAns() == answerNr) {
                option1.setBackground(ContextCompat.getDrawable(this,R.drawable.answer_correct));
                showQuestions();
            } else{
                changeToWrongColor(rbSelected);
            }
            showQuestions();
            break;
        case 2:
            if(currentQuestions.getCorrectAns() == answerNr) {
                option2.setBackground(ContextCompat.getDrawable(this, R.drawable.answer_correct));
                showQuestions();
            }
            else{
                changeToWrongColor(rbSelected);
                showQuestions();
            }
            break;
        case 3:
            if(currentQuestions.getCorrectAns() == answerNr){
                option3.setBackground(ContextCompat.getDrawable(this,R.drawable.answer_correct));
                showQuestions();}
            else{
                changeToWrongColor(rbSelected);
                showQuestions();
            }
            break;
        case 4:
            if(currentQuestions.getCorrectAns() == answerNr) {
                option4.setBackground(ContextCompat.getDrawable(this, R.drawable.answer_correct));
                showQuestions();
            }
            else{
                changeToWrongColor(rbSelected);
                showQuestions();
            }
            break;

    }// end of the Switch/case
    if(questionCounter == 10)
        nextbutton.setText("Confirm and finish the quiz");
}

private void changeToWrongColor(RadioButton rbSelected) {

  rbSelected.setBackground(ContextCompat.getDrawable(this,R.drawable.answer_wrong));
}

0 Answers0