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 trialfadel fadel
Courses Plus Student 322 Pointsconsole.readLine doesn't work on netbeanes
this is the code : package edxjavatest; import java.io.Console;
public class EdxJavaTest {
public static void main(String[] args) {
Console console =System.console();
String treeHouse = console.readLine("enter text");
}}
it gives me this : Exception in thread "main" java.lang.NullPointerException at edxjavatest.EdxJavaTest.main(EdxJavaTest.java:25) Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
3 Answers
Craig Dennis
Treehouse TeacherHi fadel fadel !
Some IDEs have problems with the java.io.Console object. What IDEs, like NetBeans, typically do is wrap the input and output so that they can write to a pane in the Application. Unfortunately the Console class is final, so it makes it hard for them to override things. It will work if you write it in NetBeans and run from your command line. Let me know if you need help doing that.
It's been a bug for quite some time, hopefully they'll fix it. In future courses, I'll switch to use a different method of writing and reading, System.out and System.in and it will work in NetBeans.
Hope that helps!
rtholen
Courses Plus Student 11,859 PointsIs this all your code? The error occurs on line 25 and I don't see 25 lines of code. The code as stated works since I was able to compile and run it.
fadel fadel
Courses Plus Student 322 Pointsyes this is all the code . did you use netbeanes IDE ?
rtholen
Courses Plus Student 11,859 PointsI am not using netbeans. I compiled your code in a console window successfully and ran it.
fadel fadel
Courses Plus Student 322 Pointsfadel fadel
Courses Plus Student 322 Pointsthank you