i start reading "java core" book and when i try to compile and run this code
import java.io.Console;
public class Test {
public static void main(String[] args) {
Console cons = System.console();
String name = cons.readLine("enter user name: ");
System.out.println(name); } }
first with netbeans 9.0 i get this error
Exception in thread "main" java.lang.NullPointerException
at Test.main(Test.java:8)
/home/ahmed/NetBeansProjects/Test/nbproject/build-impl.xml:1328:
The following error occurred while executing this line:
/home/ahmed/NetBeansProjects/Test/nbproject/build-impl.xml:948: Java returned: 1
BUILD FAILED (total time: 0 seconds)
but when i try to compile and run the same code with javac Test.java
then java Test
no errors are generated and the code runs perfectly
what does this means and how to fix it ?