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

Why can't i use printf and readLine in eclipse?

Hey so i recently started learning Java but when i try to code in eclipse instead of treehouse's code editor then it wont work i asked someone and he said i had to use: System.out.println("Enter a line of text: "); instead of readLine I am just a bit confused because the course are showing different methods

1 Answer

Ali Nawab
Ali Nawab
13,869 Points

Are you using the Console's readLine method? If so then yes, it won't work in Eclipse since the IDE can't see a console (by default) and will always produce a null object. Running your java file within a shell, however, will solve the problem. This happens because when you run your code in eclipse it uses a process where no console is present, but when running the code within a shell (for example using Window's cmd 'java' command to run your class) will have a console and therefor the Console object won't be null.