Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

I'm getting an error.

Hey, in java eclipse when I run my code I get an error. Source code: import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
    /*  Some terms:
        noun - Person, place or thing
        verb - An action
        adjective - A description used to modify or describe a noun
        Enter your amazing code here!
    */
    // __Name__ is a __adjective__ __noun__. They are always __adverb __verb__.
    String ageAsString = console.readLine();
    int age = Integer.parseInt(ageAsString);
    if (age < 13) {
      console.printf("Sorry, you must be at least 13 to use this program.\n");
      System.exit(0);
    }
    String name = console.readLine("Your name:  ");
    String adjective = console.readLine("Name an adjective:  ");
    String noun = console.readLine("Name an noun:  ");
      if (noun.equalsIgnoreCase("dork") || 
          noun.equalsIgnoreCase("jerk")) {
       console.printf("That language is not allowed.\n\n  Exiting... \n\n");
       console.printf("That language is not allowed.\n\n  Exiting... \n\n");
       System.exit(0);
      }

    String adverb = console.readLine("Name an adverb:  ");
    String verb = console.readLine("Name an verb:  ");
    console.printf("%s is a %s %s. They are always %s %s.\n", name, adjective, noun, adverb, verb);
}

}

the error is: Exception in thread "main" java.lang.NullPointerException at Test.main(Test.java:14)

Gabe Olesen
Gabe Olesen
1,606 Points

Hey,

The reason why you're getting error message "Exception in thread "main" java.lang.NullPointerException" is because the the java.io.Console runs your code at the command line i.e. CMD.

I would advise to use the workspace to test code until we all get closer to using IDE's (Integrated Development Environment) like Eclipse.

Hope this helped!

~Gabe