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 Objects (Retired) Creating the MVP Prompting for Guesses

ShaoHsuan Duan
ShaoHsuan Duan
6,044 Points

Got 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?

Raymond Wach
Raymond Wach
7,961 Points

If 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

class HelloWorld {
    public static void main (String[] args) {
        System.out.println("Hello, world!");
    }
}
ShaoHsuan Duan
ShaoHsuan Duan
6,044 Points

Thank 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
Raymond Wach
7,961 Points

Yeah, 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
STAFF
Craig Dennis
Treehouse Teacher

If 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
ShaoHsuan Duan
6,044 Points

Thank 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
Tony Brackins
28,766 Points

I got this working with TextIO.java instead of console. FYI