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 trialShaoHsuan Duan
6,044 PointsGot errors when I'm trying to run this code in Eclipse
Hello, I'm getting errors when running this code in Eclipse.
My code runs without a problem in workspace and I don't see any error when editing it in Eclipse until I run it.
The error says: Exception in thread "main" java.lang.NullPointerException at Prompter.enterChar(Prompter.java:12) at Hangman.main(Hangman.java:7)
I'm assuming there's some kind of setting error I made in Eclipse since this code actually works in the workspace.
update:
I just found that what I'm encountering seems to be a existing problem in many IDEs include Eclipse.
This may be irrelevant to the project but I would like to know if there is anyway I can test my code in Eclipse like what we can do in workspace's console?
ShaoHsuan Duan
6,044 PointsThank you Raymond. I was confused about how to organize my code in the forum correctly, which is the reason why I didn't include my code in my question.
Raymond Wach
7,961 PointsYeah, they don't make it very easy to share code from what I've seen (I really wish we had line numbers). The best I've seen for Java is to do one code block per file and preface each block with the name of the file.
Something along the lines of:
Foo.java
class Foo {
}
Bar.java
class Bar {
}
I've also seen some pretty long questions with a lot of code in them so I wouldn't worry too much about length. If it really bothers you, I guess you could post each file as a code block in a comment to your question with one comment per file.
2 Answers
Craig Dennis
Treehouse TeacherIf you run this from your machine (not using Eclipse > Run) it will work just like it does in Workspaces. The problem is java.io.Console
isn't wired up in Eclipse.
IDEs are coming soon!
ShaoHsuan Duan
6,044 PointsThank you sir. It works on my machine. I guess I'm staying with the Treehouse workspace at this time because I don't want to have an extra cmd console on my screen. Don't know how so many people can use this popular IDE without having an internal console...
Tony Brackins
28,766 PointsI got this working with TextIO.java instead of console. FYI
Raymond Wach
7,961 PointsRaymond Wach
7,961 PointsIf you include the code you are running that would help you to get better feedback in the forum.
Remember, you can wrap you code in triple backticks to get Treehouse to apply some nice code styling:
```java
class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello, world!");
}
}
```
will be displayed as