-3

If i run this code below in Netbeans

import java.io.Console;
public class Introduction {        
    public static void main(String[] args) {
        Console console= System.console();// creates a java Object which has method that allows us to write
        console.printf("Hallo parvel");
    }        
} 

It gives me the error:

Exception in thread "main" java.lang.NullPointerException
    at Introduction.main(Introduction.java:10)
/home/parvel/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds). 

please help

Pons
  • 1,101
  • 1
  • 11
  • 20
parvel
  • 11
  • 1
  • 6

2 Answers2

0

java.io.Console object is null because there is no console attached to it.

Try to run from command line or attached console to it.

Find more details about it here: https://netbeans.org/bugzilla/show_bug.cgi?id=111337

Abhilekh Singh
  • 2,845
  • 2
  • 18
  • 24
0

You need to run this from a terminal using java -jar myjar.jar

In order to have this print to console using System.console();

You will need to export this as a runnable jar

then you can run java -jar myjar.jar and it will output Hallo parvel

Robert I
  • 1,509
  • 2
  • 11
  • 18