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

Sephiroth A
Sephiroth A
327 Points

Hi my question is why doesn't the Console work in eclipse. I tried using it but the compiler is showing an error.

public class Console {

public static void main(String[] args) {
        Console console = System.console();
        console.printf("Abdi");
}

}

Sephiroth A
Sephiroth A
327 Points

Sorry , just realised I called the class Console!! , thanks.

3 Answers

same here it shows an error message

Exception in thread "main" java.lang.NullPointerException

when i run this on eclipse

import java.io.Console; public class input { public static void main(String[] args) { Console console = System.console(); console.printf("this is printf"); } }

Nana Baisie
Nana Baisie
8,535 Points

I hope you have found the solution to your problem, if not;

According to your code: import java.io.Console; public class input { public static void main(String[] args) { Console console = System.console(); console.printf("this is printf"); } }

the name of your public class is "input", so save your file as "input.java" and it should work fine.

Kris B
Kris B
11,583 Points

Have you imported java.io.Console? If not add the following to the very top:

import java.io.Console;

Eclipse is pretty good at giving you feedback about errors, it should underline any errors in red. If you see any red lines hover over them and it'll give you some feedback, possibly telling you how to fix the error. Although remember Eclipse doesn't know what you're doing, some of the fixes will just suppress the error, not fix the problem in an appropriate way, so it's always good to ask or Google. :)

thank you for replying back but as you can see my code, i have already imported java.io.console . i will google about it. :)

Pragyanshu - have you found an answer to your question?