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 Getting Started with Java Receiving Input

Eclipse 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

your console.printf is incorrect it should be like this: console.printf("Hi,my name is %s\n,firstName);

4 Answers

Josip Dorvak
Josip Dorvak
18,126 Points

Would I be able to see your entire program? Also if console.printf isn't working, you can always use System.out.printf() instead

In 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);
} }

I get the same error too. Does someon have a solution? Eclipse shows an error also when i try to use the readLine method.

The 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);