I am building an application in Java (using NetBeans) that accepts user input through the console and prints out a statement using their name (given in user input). The following is the code:
package amazingpets;
import java.io.Console;
public class AmazingPets {
public static void main(String[] args) {
Console console = System.console();
String firstName = console.readLine("What is your name? ");
console.printf("My name is %s.\n",firstName);
}
}
However I keep getting the following error in the console:
Exception in thread "main" java.lang.NullPointerException
at amazingpets.AmazingPets.main(AmazingPets.java:14)
Java Result: 1
Can anyone please suggest a possible solution?