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

Rokas Mazeika
Rokas Mazeika
4,243 Points

Something wrong

Java Objects - Validation

i am trying to make the code a little bit different but i get some syntax errors. variable guess might not have been initialized: return mGame.guess(guess);

https://w.trhou.se/jn53s4flk0

1 Answer

Grzegorz Kończak
Grzegorz Kończak
10,782 Points

Quick and dirty fix would be to just initialize guess variable on line 15 of prompter class like: char guess = 0;

For the rest of the application if you want to stick to good practices don't make public fields - private class fields and getters/setters are the way to go :) Also everywhere i looked (learning materials i mean) class names started with capital letters, on first looking of your code I was like "what happend here?? I always thought it should be Game game or something...":

public prompter(game Game) { mGame = Game; }

then again it compiles so from compiler standpoint it's all good ;)