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 Build a Simple Android App (2014) Basic Android Programming Generating a Random Number

CD Lim
CD Lim
4,782 Points

factLabel is highlighted in pink

Hi my factLabel is highlighted in pink and I can't convert the randomNumbers into strings

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fun_facts); //declare our view variables and assign the views from the layout files final TextView factLabel = (TextView) findViewById(R.id.factTextView); final Button showFactButton = (Button) findViewById(R.id.showFactButton); final View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view){ // the button was clicked, it will update the with some new facts String fact = ""; // Randomly select a fact Random randomGenerator = new Random(); //construct a new Random generator int randomNumber = randomGenerator.nextInt(3); /* convert randomNumber in a text fact * 0 = Ants stretch when they wake up in the morning * 1 = Ostriches can run faster than horses * 2 = Olympic Gold metals are usually made mostly of silver */ // if randomNumber equals to zero then if (randomNumber == 0) { // set fact equals to ants fact fact = "Ants stretch when they wake up in the morning"; }

            else if (randomNumber == 1) {
                fact = "Ostriches can run faster than horses";

            else if (randomNumber == 2) {
                fact = "Olympic Gold metals are usually made mostly of silver";

            else {
                fact = "Sorry there was an error";
            // update the label with our dynamic fact
Sina Maleki
Sina Maleki
6,135 Points

did you initialize the fact variable with empty blank first like below? fact = ""; Cheers,