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 Java Basics Using your New Tools Multiple Strings

code wont work in eclipe luna

so here is the code

package learning1;

import java.io.Console;

public class Introductions {

public static void main(String[] args) {
    Console console = System.console();
    // Welcome to the Introductions program!  Your code goes below here

String doge = console.readLine("type random word here: \n");

console.printf("wow your cool %s \n", doge); } }

here is the error

Exception in thread "main" java.lang.NullPointerException at learning1.Introductions.main(Introductions.java:10)

1 Answer

Christopher Augg
Christopher Augg
21,223 Points

Stefan,

Your code is fine. It is because you are trying to use a Console within an IDE. Console is for consoles like terminal in OSX or cmd in windows. You can compile your code by using one of them and typing in the commands Dennis went over:

javac Introductions.java

java Introductions

However, an easy way to use the IDE is to use Scanner instead.

       import java.util.Scanner;

       public class Introductions {

       public static void main(String[] args) {

         System.out.println("type random word here: \n");
         Scanner input = new Scanner(System.in);

          // Welcome to the Introductions program!  Your code goes below here
          String doge = input.nextLine();

          System.out.printf("wow your cool %s \n", doge); } }

Hope this helps.

Regards,

Chris