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

bahati kayombo
bahati kayombo
Courses Plus Student 177 Points

need some help with creating a string variable etc

getting an error when running the string

Random randomGenerator = new Random();

int randomNumber = randomGenerator.nextInt(10);

intAsString [] facts = {"my name is B"};

intAsString fact = "";

1 Answer

Ben Jakuben
Ben Jakuben
Treehouse Teacher

There are a few syntax errors in the lines you've added. Let's start over with these two lines:

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

Next, you want to declare a variable and then make it a String type. For a new variable, we always start with the data type first, so your next line would start with:


With that, we need to give the new variable a name, so we'd have:

String intAsString

We could stop right here and have an empty, or uninitialized variable, if we add a semicolon like this:

String intAsString;

(Remember that all statements in Java like this need to end in a semicolon.)

But wait, there's more! We want to store a text value in this variable! What operator do we use to put a value in a variable? Here's a hint: look at the provided line that declares the randomNumber variable.

That should get you started, but I don't want to give away the whole answer. Hopefully that's enough, but let us know if you need more help after trying it again.