Possible Duplicate:
System.Console() returns null
Code:
public class Demo {
public static void main(String[] args){
Console c = System.console();
if (c == null) {
System.err.println("No console.");
System.exit(1);
}else {
System.out.println("Console is.");
System.exit(0);
}
}
}
always No console. Why ? How to fix? Thanks.
You don't have any console associated.
As per javadoc
EDIT:
From Console javadoc.
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.