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 trialAyomi Meneko
176 PointsHow can I solve this error answer.setText(answer);
Please how can I solve the error: answer.setText(answer); because it is not making my Crystal Ball emulator run.. I need help.
with an answer
String answer = "Yes";
answer.setText(answer);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
3 Answers
michaelpavle
555 PointsI think you need to add these lines of code: ***Java String answer = "";
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(3);
answer = Integer.toString(randomNumber);
if (randomNumber == 0){
answer = "Yes!";
}
else if (randomNumber == 1){
answer = "No";
}
else if (randomNumber == 2){
answer = "Maybe.";
}
else{
answer = "Sorry, there has been an error.";
}
answerLabel.setText(answer);
}
});
}
Ayomi Meneko
176 PointsI need help on it seriously
michaelpavle
555 PointsWhen I checked the code, you wrote answer.setText(answer); and not answerLabel.setText(answer);
Ayomi Meneko
176 PointsAyomi Meneko
176 Points@michaelpavle Thanks for your help but this is the complete program but it is always showing there is error here : answerLabel.setText(answer); .. It shows red underline and I don't know how to fix it
package com.puritywordview.crystalgaze;
import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button;
public class MainActivity<TextView> extends ActionBarActivity {
}