Java Java Objects (Retired) Creating the MVP Prompting for Guesses

Dominik Huber
Dominik Huber
4,631 Points

Console console = System.console() --> Why is it not working in my IDE?

Hi,

I took this course the 2nd time. Now doing everything without workspace but with my own IDE (Intellij). So now I encountered a problem:

I cant use Console console = System.console() --> It just won't work. Can anyone explain me why it's not working outside of the IDE but it's working on the teamtreehouse workspace?

I have a fix for this:

Scanner scanner = new Scanner(System.in); System.out.println("Please enter a letter: "); String guessAsString = scanner.next();

But I want to understand why it's not usable in IDE.

I found t his: http://stackoverflow.com/questions/4644415/java-how-to-get-input-from-system-console

I'm wondering what's meant by "usable only outside IDE" ? Where else could you write a programm?

Thx!

2 Answers

Jeremy Hill
Jeremy Hill
21,739 Points

I could not get it to work in my IDE either. I usually use a Scanner object from importing java.util.Scanner.

Alexander Nikiforov
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,136 Points

You can compile and run the program in Unix console/terminal with Console console code.

That is exactly what they have in Workspaces: Unix console with Bash.

Depending on your OS: you can one start terminal, download files from the workspace and run just like in workspace:

javac Class.java and then java Class

If you want to learn why Console is not working in IDE, try for example this discussion:

http://stackoverflow.com/questions/26470972/trying-to-read-from-console-java

See the best answer voted: guy gives pretty explicit explanation