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 trialSephiroth A
327 PointsHi 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");
}
}
3 Answers
pragyanshu kukreti
Courses Plus Student 157 Pointssame 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
8,535 PointsI 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
11,583 PointsHave 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. :)
pragyanshu kukreti
Courses Plus Student 157 Pointsthank you for replying back but as you can see my code, i have already imported java.io.console . i will google about it. :)
Luis Reyes
11,719 PointsPragyanshu - have you found an answer to your question?
Sephiroth A
327 PointsSephiroth A
327 PointsSorry , just realised I called the class Console!! , thanks.