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 Basic Android Programming Using the Random Class

bahati kayombo
PLUS
bahati kayombo
Courses Plus Student 177 Points

need some help with creating a string variable etc

getting an error when running the string

RandomTest.java
Random randomGenerator = new Random();

int randomNumber = randomGenerator.nextInt(10);

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

intAsString fact = "";

1 Answer

Ben Jakuben
STAFF
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:

String

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.