Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App Basic Android Programming Using the Random Class

Need Help On Last Task!

when I run this code it keeps giving me an error where it says int can not be converted into string? So please someone help me!

RandomTest.java
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = "";
intAsString = (10);

3 Answers

Suleyman Orazgulyyev
PLUS
Suleyman Orazgulyyev
Courses Plus Student 5,798 Points

You are declaring a string "intAsString" and you are assigning 10 to it. Either you have to cast it, or use a method:

Integer.toString(intAsString)

Rafael Miranda
Rafael Miranda
17,121 Points

I would do like this...

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = String.valueOf(10);

Hi Jesse,

The challenge is looking for you to use a moosh, i.e. adding a blank string to an integer to create a string*of* that integer.

String intAsString = randomNumber + "";

I hope that helps,

Steve.