Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Extra Credit: Random Acts of Kindness How to do it?

How to do this? How to connect the random integer numbers with text?

What is it you're trying to do, exactly?

This an extra credit "Random Acts of Kindness" under Basic Android Programming course with following task: See if you can figure out how to add messages to the TextView based on the random numbers you are generating. Congratulate the user for certain numbers with messages like, "Surprise! You win!" or "Nice job pressing that button, superstar!"

                String fact = "";
                //Randomly select a fact
                Random randomGenerator = new Random(); // Construct a new random generator
                int randomNumber = randomGenerator.nextInt(3);
                fact = randomNumber + "";
                if (randomNumber = 0){ //Error - Required: boolean Found: int
                    fact = "text1";
                }
                else if (randomNumber = 1){ //Error - Required: boolean Found: int
                    fact = "text2";
                }
                else if (randomNumber = 2){ //Error - Required: boolean Found: int
                    fact = "text3";
                }
                //Update the label with our randomly generated text
                factLabel.setText(fact);
            }
        };

Android studio error Required: boolean Found: int - how to fix it?

1 Answer

This works :)

String fact = "";
                //Randomly select a fact
                Random randomGenerator = new Random(); // Construct a new random generator
                int randomNumber = randomGenerator.nextInt(3);
                if (randomNumber == 0) {
                    fact = "text1";
                }
                else if (randomNumber == 1) {
                    fact = "text2";
                }
                else if (randomNumber == 2) {
                    fact = "text3";
                }
                //Update the label with our randomly generated text
                factLabel.setText(fact);