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 trialDavid Esquivel
977 Pointsto.String
this is for the answer = Integer.toString(randomGenerator); eclipse shows an error for .toString Please help me out
2 Answers
Iskandar Fendi
5,700 PointsHi David,
What does the error said? I suspect: What is your randomGenerator type? Is it Random class? If it is it will give you an error. .
David Esquivel
977 PointsIt is Random class I think
Iskandar Fendi
5,700 PointsYes, it is! The error is when you put:
answer = Integer.toString(randomGenerator). In order to fix it, change it into:
answer = Integer.toString(randomNumber);
It will fix the problem.
In your Eclipse, it should tell you why (I assume "Type Don't Match").The reason for your error is:
You put in a Random Class Type instead of Integer.
In programming, you can look up toString() method in Java API
It says: static String toString(int i)
It takes integer type inside of it.
Please let me know the updates
David Esquivel
977 PointsI changed it but the error is still the same. I have the error text in the comments on my question I see what you're saying though. It should work, but it won't
David Esquivel
977 PointsIt's working now! Thanks!
Victor Rodriguez
15,015 Pointsare you trying to take a random Number that you generated and save it as a string? if so use:
answer = randomGenerator.toString();
The toString() method should not be taking any parameters, unless you overrode the method. It is normally used: variable.toString()
David Esquivel
977 PointsDavid Esquivel
977 PointsThis is what I have:
This is the Error text: The method toString(int) in the type integer is not applicable for the arguments (Random)