• Post Reply Bookmark Topic Watch Topic
  • New Topic

System.console() returns null  RSS feed

 
Vlad Shelkovtsev
Greenhorn
Posts: 4
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I bet I'm like the 1000th guy who asks about this, but well...

I'm trying to compile something like the code above in Eclipse . The problem is that System.console() returns null, and for that reason the NullPointerException is thrown at 11.
When I'm compiling the same code through the command line it seems to work fine.
As far as I understand JVM somehow has no console, when started through Eclipse. Is there a way to run this in Eclipse without significant changes in the code?

Thank you in advance!

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is my understanding that there is no console when starting a JVM inside of an IDE, so the answer is likely no (it's actually "no" to the more general question of "Is there a way to run this in an IDE?").
 
Vlad Shelkovtsev
Greenhorn
Posts: 4
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is my understanding that there is no console when starting a JVM inside of an IDE

Hmm... It seems to be so, but it's funny. Is there a particular reason why it is that way? Is it a bug or a feature?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess (and that's all it is) would be that there is already a console -which belongs to the IDE's JVM- and that a child process can't have another one. That's how I read the relevant excerpt from the javadocs:
Console javadocs wrote:Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!