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 trialkirianna grimaldo
307 Pointswhat does it mean when it says String cannot be converted to int
i have try every thing i know and it keeps saying the same thing
String answerToLife = "42";
int answer = ("answerToLife");
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, kirianna grimaldo! The answerToLife
variable is a String. And we want to create a new integer named answer
that holds the Integer version of that String. So we have to do something called "parsing". This means that Java will look at that string and see if it can make it into an integer we can perform mathematical operations on later.
Some "numbers" aren't ever actually used as numbers. Your social security number or your credit card number for example aren't used for mathematical manipulations. Adding 2 to your social security doesn't really do anything except possibly refer to another person.
I highly suggest you review the previous video especially the part around 2:29 where Craig specifically uses Integer.parseInt
to turn a string into its numerical equivalent.
Hope this helps, but let me know if you're still stuck!