java – How to detect a click event of a button outside another method-ThrowExceptions

Exception or error:

Please find below the code I have implemented.

I need to detect the click event of the button outside another method.

 public List<CorrectAnswer> passSessionIdTogetResults(String id) {

    db = this.getReadableDatabase();
    List<CorrectAnswer> correctAnswerList = new ArrayList<>();
    CorrectAnswer correctAnswer = new CorrectAnswer();

   Cursor cursor2 = db.rawQuery("SELECT * FROM table_test_start WHERE test_start_id ="+id,null);
   if(cursor2.moveToFirst()){

       do{

          String question_number= cursor2.getString(cursor2.getColumnIndex(ID_TEST));
          String question_id = cursor2.getString(cursor2.getColumnIndex(QUESTION_ID_TEST_START));
          String selected_option =  cursor2.getString(cursor2.getColumnIndex(SELECTED_OPTION_TEST_START));
          Cursor cursor = db.rawQuery("SELECT * FROM practice_questions WHERE question_content_id='"+question_id+"' AND question_answer='"+selected_option+"'", null);
           if (cursor.moveToFirst()) {
               String green = "green";

               correctAnswer.setCorrect_anwer_green(green);


               Log.d("DbHelper","Question ID "+question_id);
               Log.d("DbHelper","Correct Answer "+green);


           }else {

               String red = "red";
               correctAnswer.setWrong_answer_red(red);

               Log.d("DbHelper","Question ID "+question_id);
               Log.d("DbHelper","Wrong Answer " +red );
           }
           correctAnswer.setCorrect_id(question_number);
           correctAnswer.setQuestion_number_id(question_id);
           correctAnswer.setSelected_set_options(selected_option);
           correctAnswerList.add(correctAnswer);


      }while(cursor2.moveToNext());


    }


  return correctAnswerList;
}

Getting last value of and inserted for n times.

How to solve:

Try this

  String question_number= cursor2.getString(cursor2.getColumnIndex(ID_TEST));
  String question_id = cursor2.getString(cursor2.getColumnIndex(QUESTION_ID_TEST_START));
  String selected_option =  cursor2.getString(cursor2.getColumnIndex(SELECTED_OPTION_TEST_START));
  Cursor cursor = db.rawQuery("SELECT * FROM practice_questions WHERE question_content_id='"+question_id+"' AND question_answer='"+selected_option+"'", null);
   cursor.moveToFirst()
   do{
       String green = "green";

       correctAnswer.setCorrect_anwer_green(green);

       Log.d("DbHelper","Question ID "+question_id);
       Log.d("DbHelper","Correct Answer "+green);



   correctAnswer.setCorrect_id(question_number);
   correctAnswer.setQuestion_number_id(question_id);
   correctAnswer.setSelected_set_options(selected_option);
   correctAnswerList.add(correctAnswer);
} while(cursor2.moveToNext());

Leave a Reply

Your email address will not be published. Required fields are marked *