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 trialMichael Bredthauer
13,429 PointsProblems with TreeStory Challenge Task 1, giving me compiler error that doesn't make sense.
I am on the challenge for Java TreeStory and the first challenge says to create a new variable that accepts input. I am using the String name = console.readLine(); and it gives me this compiler error that I don't understand. What is wrong with my code?
// I've imported java.io.Console for you. It is stored in a variable called console for you.
String name = console.readLine();
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Michael,
It's not so much your code, as it is a poorly worded question. The challenge assumes you will know that because the variable is called "name" you will ask for someone's name. Just add that text to the method call and your code will pass.
String name = console.readLine("What is your name? ");
Keep Coding!
Michael Bredthauer
13,429 PointsIm glad you asked that because that was curious to me, I passed the challenge which was a bit annoying since I did that before and it didn't work but whatever as long as I know that I am on the right track.
Tatenda Mushayakarara
2,447 Pointsyeah it does..but i'm tempted to dive into that args type Object parameter.thanks
Tatenda Mushayakarara
2,447 PointsTatenda Mushayakarara
2,447 Pointshey jason i have a sort of inappropriate question. i checked the readLine documentation "https://docs.oracle.com/javase/7/docs/api/java/io/Console.html#readLine%28%29" and the method as shown is not accepting parameters. can you please explain or elaborate. i'm just taking a interest.
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsHi Tatenda Mushayakarara
That second definition doesn't, but the first one does. It takes a String to provide a formatted prompt.
So, it can do both... provide a formatted string and capture the response, or it can just "read a single line of text from the console." This challenge in particular wants the first one.
I hope that clears it up. :)