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 trial

Java Java Basics Getting Started with Java IO

Hello, 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

Which task are you talking of?

There 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

Oh okay. You are welcome.

2 Answers

Rui Bi
Rui Bi
29,853 Points

This 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.

Thank you for your help!

Kevin Goodwin
Kevin Goodwin
713 Points

If 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.

Thanks a lot - that was what I needed :)