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 trialstevengoeller
2,469 PointsEclipse Luna - console library error
Hi,
I am using eclipse for Android App course and I keep getting an error whenever I compile this "console.printf("Hi, my name is %s", firstName);"
This is the exception it throws:
Exception in thread "main" java.lang.NullPointerException at INTRO.Introductions.main(Introductions.java:9)
What I can gather is it thinks the console variable is pointing at nothing. What I don't understand is why it compiles fine in command prompt? Maybe Eclipse uses a different compiler?
So if anyone uses eclipse and give me some pointers it would be great.
Thank you
4 Answers
Josip Dorvak
18,126 PointsWould I be able to see your entire program? Also if console.printf isn't working, you can always use System.out.printf() instead
Ellone B
15,575 PointsIn eclipse you can use Scanner, like this :
import java.util.Scanner;
public class introduction{
public static void main(String[] args)
{
Scanner unSC = new Scanner (System.in);
String firstName = "Graig";
System.out.println("Hello my name is "+firstName);
}
}
Itai Shin
9,928 PointsI get the same error too. Does someon have a solution? Eclipse shows an error also when i try to use the readLine method.
Michael Arsenault
15,352 PointsThe Console class returns a NULL POINTER in pretty much every IDE out there.
For this issue, use:
Scanner scan = new Scanner(System.in);
System.out.print("What do you want to say? ");
String s = scan.nextLine();
System.out.print("\n\n" + s);
channonhall
12,247 Pointschannonhall
12,247 Pointsyour console.printf is incorrect it should be like this: console.printf("Hi,my name is %s\n,firstName);