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
Ian - PortalPacific
Courses Plus Student 3,518 PointsInstead of 0, 1, 2 random numbers. It's showing "Java.until.Random@xxxxxxxx"
So i am following the tutorial located here: http://teamtreehouse.com/library/build-an-android-app/basic-android-programming/generating-a-random-number
The video lesson ends with him getting random numbers between 0-2. My results are similar to his but instead of numbers 0-2, i'm getting text that says Java.until.Random@xxxxxxxx and whenever you press the "Show Another Fun Fact!" Button; it displays another/different Java.until.Random@xxxxxxxx.
(The xxxxxxxx's is in place of whatever random letters/numbers it generates.)
Thanks for any insight!
public class FunFactsActivity extends Activity {
@Override
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 file.
final TextView factLabel = (TextView) findViewById(R.id.factTextView);
Button showFactButton = (Button) findViewById(R.id.showFactButton);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
//button was clicked so now update fact label with a new fact.
String fact = "";
//Randomly select a fact.
Random randomGenerator = new Random(); //Construct new random generator.
int randomNumber = randomGenerator.nextInt(3);
fact = randomGenerator + "";
//Update the label with our dynamic fact.
factLabel.setText(fact);
}
};
showFactButton.setOnClickListener(listener);
}
}
1 Answer
Justin Horner
Treehouse Guest TeacherHello Ian,
From your code, it appears you are setting the fact variable to the Random object instead of the random number that you generated.
So it would be
fact = randomNumber + "";
Instead of
fact = randomGenerator + "";
I hope this helps! If you need further explanation feel free to ask.
Ian - PortalPacific
Courses Plus Student 3,518 PointsIan - PortalPacific
Courses Plus Student 3,518 PointsAppreciate it! Thanks!
Ian - PortalPacific
Courses Plus Student 3,518 PointsIan - PortalPacific
Courses Plus Student 3,518 PointsJustin Horner
For some reason when i click the "Show Another Fun Fact" Button the screen on the genymotion simulator goes black but if i keep clicking (which it lets me) it comes back on. Do you know why that could be?
Justin Horner
Treehouse Guest TeacherJustin Horner
Treehouse Guest TeacherYou're welcome!
Justin Horner
Treehouse Guest TeacherJustin Horner
Treehouse Guest TeacherI have not encountered this myself. If you are experiencing blinking, you might want to check this out. Basically, the person solves the blinking issue by reinstalling Genymotion.