• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

System.console()

 
Ranch Hand
Posts: 45
2
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The above piece of code waits for me to enter something in the console. But the following code:-



does not wait at all throws a null pointer as soon as I run.
I am using eclipse and Intellij to simulate the same. Behavior in both the IDE's are same.
 
Ranch Hand
Posts: 62
5
Eclipse IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jacky Stark wrote:

does not wait at all throws a null pointer as soon as I run.


In order to use java.io.Console, you must have a "real" console, one that is provided by your operating system (e.g. the Command prompt on Windows).
Not the Console "view" in Eclipse, which is not a real console.
 
Jacky Stark
Ranch Hand
Posts: 45
2
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrea, you mean to say that instead of IDE I should try to execute the code using conventional methods?...
 
Andrea Binello
Ranch Hand
Posts: 62
5
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jacky Stark wrote:instead of IDE I should try to execute the code using conventional methods?...


Yes, you have to open the Command prompt/Console of your OS, then change the current directory (if necessary and where appropriate), then launch java etc ... with appropriate options and arguments (here depends if you have created a single jar or distinct .class files and if -classpath option is necessary)
reply
    Bookmark Topic Watch Topic
  • New Topic