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 trialmichaldr2
4,500 PointsHello, the challenge doesn't pass when the method readLine is left with empty parenthesis
Hi,
in the question there is no info about a message to be included in parenthesis. The challenge only works when you do it as in the lecture. I passed it, but I believe it could be misleading.
Greetings,
Michal
michaldr2
4,500 PointsThere was a bit unclear for me what should be in parenthesis (i.e. challenge 1 of4). Now I know that this method requires a string even it is empty (""). Thank you for your response, Michal
Gloria Dwomoh
13,116 PointsOh okay. You are welcome.
2 Answers
Rui Bi
29,853 PointsThis is because the Console object's readLine() method has a parameter of the String type.
In Java, methods have, "method signatures," which must specify the parameters and return type.
Thus, to call Console's readLine() object, we will need to provide the right method signature for our call, which in this case is a parameter of the type String.
Hence, when you want to call the method, readLine(), you have to pass it a string to display to the user. Technically, if you don't want to pass a prompt to the user, you can just pass it an empty string, which is "". Then when the user is prompted, they are shown a blank String.
console.readLine("");
Also note that you must use double-quotes in Java, single-quotes are reserved for a different type, char.
michaldr2
4,500 PointsThank you for your help!
Kevin Goodwin
713 PointsIf you write:
Java String example = console.readLine();
then because the readLine method requires parameters in the form of a string, It would cause an exception and crash.
This proper format is you don't want to include a string in a form of and output message would be:
Java String example = console.readLine("");
Having the empty quotation marks states, that there is indeed a string, it just happens to be empty.
I hope this helps you understand.
michaldr2
4,500 PointsThanks a lot - that was what I needed :)
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsWhich task are you talking of?