Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Getting Started with Java Receiving Input

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

package coding;

import java.io.Console;

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
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,703 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.