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 trialSchwartz Prince
Courses Plus Student 2,132 PointsNot getting the answer.
My code shows me error. Couldn't fix it.
int answer = Integer.parseInt(answerToLife);
2 Answers
Steve Hunter
57,712 PointsHi there,
I think you should try again; your code looks fine. This just worked for me:
String answerToLife = "42";
int answer = Integer.parseInt(answerToLife);
Steve.
Schwartz Prince
Courses Plus Student 2,132 PointsThank you for the response Steve. Its working now.
Steve Hunter
57,712 Points
Schwartz Prince
Courses Plus Student 2,132 PointsSchwartz Prince
Courses Plus Student 2,132 PointsHi Steve,
Thank you for your response. I tried again. But, it shows the same error message.
JavaTester.java:73: error: class expected int answer = Integer.parseInt(int.answerToLife) ^
It would be great if you can help me in this.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsTwo things: first, don't delete the first line; make sure you have the
String answerToLife = "42";
line in there. Second, don't haveint.answerToLife
in the second line; just useanswerToLife
as the parameter inside the brackets/parenteses forparseInt()
.Try those. If neither works, post your whole code in and we'll get this sorted.
Steve.