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 trialdanielcook5
1,005 PointsError Parsing my Integer
So I declared the variable ageAsInt, like in the video, and when I type Integer.parseInt(ageAsInt); and compile it it says it can't recognize the variable I declared.
I have checked for typos and messed around, and it doesn't want to work. Please note that I am a beginner in Java.
2 Answers
Alison Brodribb
24,615 PointsHi Daniel (Just adding this as an answer as I accidentalyl added as a comment)
From what you've written in your question, it looks like you're trying to parse your integer ageAsInt into the parseInt method, when you need to parse in a string.
Your code should look something like this:
String ageAsString = "some number input as String"; int ageAsInt = Integer.parseInt(ageAsString);
danielcook5
1,005 PointsWorked for me! Thanks a lot, Alison!
Alison Brodribb
24,615 PointsAlison Brodribb
24,615 PointsHi Daniel
From what you've written in your question, it looks like you're trying to parse your integer ageAsInt into the parseInt method, when you need to parse in a string.
Your code should look something like this:
String ageAsString = "some number input as String"; int ageAsInt = Integer.parseInt(ageAsString);