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

Help using Console on Eclipse

I have made a mad libs on the workspace here and it works but when I move it to Eclipse I cannot type into the console... When I run it I get the error "Exception in thread "main" java.lang.NullPointerException at TestPackage.TestClass.main(TestClass.java:14)" Please help me by saying how or if I can communicate to the console on Eclipse like I do here for things such as "javac" and "clear" and jShell

In Eclipse you don't do console.printf like you do on treehouse. You can use the Scanner class.

// at the very top type in your import
import java.util.Scanner;

//next inside the class type: 

Scanner input = new Scanner(System.in);  // instantiated Scanner object here
// now to get input from the user you can type:

String string = "";
System.out.print("Type in something: ");
string = input.next(); // using object of Scanner here
System.out.printf("\nYou said:  %s.", string);

You might be able to set up the Console object to print to the console in Eclipse but I didn't have much luck with it. I haven't coded in java in a while but hopefully this helps.