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 (retired 2014) Learning the Language Objects and Random Numbers

reginald everett
PLUS
reginald everett
Courses Plus Student 1,862 Points

on challenge task 4 of 4 I input this info yet it still says im wrong. any suggestions?

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

4 Answers

Paul Stevens
Paul Stevens
4,125 Points

Hello,

I think the problem is with this line of code:

String = intAsString.toString(randomNumber);

First check the spelling of the variable String, I think it might have to be string with a lower case s (not sure), and change the intAsString to Integer, like below:

string = Integer.toString(randomNumber);

Try that and see if it helps,

Paul :)

reginald everett
PLUS
reginald everett
Courses Plus Student 1,862 Points

Declare a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: Use the toString() method of the Integer class. (thats what they told me to do)

(heres my new answer) Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(10); string = Integer.toString(randomNumber);

(here is what they are tellingme the error is) JavaTester.java:83: cannot find symbol symbol : variable string location: class JavaTester string = Integer.toString(randomNumber); ^ JavaTester.java:119: cannot find symbol symbol : variable intAsString location: class JavaTester if (intAsString instanceof String) { ^ 2 errors

Paul Stevens
Paul Stevens
4,125 Points

Ok, I will have a go.

//Declare a String variable named intAsString
String intAsString;

 //Convert the randomNumber integer to a String value and store it in the intAsString variable.
 intAsString = Integer.toString(randomNumber);

Try this. Paul :)

Paul Stevens
Paul Stevens
4,125 Points

Here is the code for the whole challenge. I have checked it and it should work for you.

/*Code from first three parts of the challenge commented out below.
 Random randomGenerator = new Random();
 int randomNumber = randomGenerator.nextInt(10);
 */

 //Declare a String variable named intAsString
 String intAsString;
 //Convert the randomNumber integer to a String value and store it in the intAsString variable.
 intAsString = Integer.toString(randomNumber);

:)