Java Java Basics Getting Started with Java Receiving Input

Exception in thread "main" java.lang.NullPointerException at coding.treehouse.main(

package coding;


public class treehouse {

public static void main(String[] args) {

    Console console = System.console();

    String firstName = console.readLine("What's your name?  ");

    console.printf("Hello my name is %s\n", firstName);



1 Answer

Brendan Whiting
Brendan Whiting
Front End Web Development Techdegree Graduate 84,607 Points

I'm not 100% sure, but I've seen people have this error before using this System.console() in their own IDE. I think the best solution is to do these exercises in the Treehouse workspace where this console is built into the environment.

Outside of Treehouse, there is more than one way of receiving input from the command line. I prefer the Scanner class.