nmalsabah / star-trek-trivia-game

0 stars 0 forks source link

Play Game button not working #5

Closed nmalsabah closed 11 months ago

nmalsabah commented 11 months ago

Issue:

The user clicks the "Play Game" button from their landing page. The app is suppose to launch the TriviaGameActivity and start the game but instead it keeps going back to the user's landing page. To debug I need to make sure the userId is being set correctly.

Debug:

private void launchUserLandingPageActivity() { int userId = user.getUserId(); // Ensure this returns a valid value Log.d("LoginActivity", "Launching UserLandingPageActivity with userId: " + userId);

Intent intent = new Intent(this, UserLandingPageActivity.class);
intent.putExtra("userId", userId);
intent.putExtra("username", user.getUserName());
startActivity(intent);
finish();

}

Log Message:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.startrek_triviagame/com.example.startrek_triviagame.TriviaGameActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x1

nmalsabah commented 11 months ago

I figured out the issue. I was setting the text for the radio buttons as an integer value but it required a string. I had to convert the integer to a string in the last line of code in this method:

private void displayTriviaQuestions() { List triviaQuestions = starTrekGameDao.getAllTriviaQuestions(); for (int i = 0; i < triviaQuestions.size(); i++) { triviaQuestionsTextViews.get(i).setText(triviaQuestions.get(i).getTriviaQuestion());

    for (int j = 0; j < triviaQuestionsRadioGroups.get(i).getChildCount(); j++) {
        RadioButton radioButton = (RadioButton) triviaQuestionsRadioGroups.get(i).getChildAt(j);

        // Convert the integer to a string before setting it
        radioButton.setText(String.valueOf(triviaQuestions.get(i).getTriviaAnswer(j)));
    }
}
nmalsabah commented 11 months ago

This has been resolved.