0

I want to write a code , using "console" class and its methods and nothing else ... code compiles correctly but there in an error and i don't understand

package ronnie;
import java.io.Console;
public class Ronnie 
{
    public static void main(String[] args) 
    { 
        Console console = System.console();
        console.printf("Hello");
    }

}

run:

Exception in thread "main" java.lang.NullPointerException
    at ronnie.Ronnie.main(Ronnie.java:8)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Zarwan
  • 5,537
  • 4
  • 30
  • 48
Mehdi Hoseini
  • 67
  • 1
  • 1
  • 7

1 Answers1

1

Per definition System.console() returns the unique Console object associated with the current Java virtual machine, if any. The NullPointerException just means that there is no console currently associated with the JVM. So you should rather write to the standard output using System.out.

Henri Benoit
  • 705
  • 3
  • 10