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 Creating the MVP Storing Guesses

Shivam Barthwal
Shivam Barthwal
2,365 Points

Please help: Getting 'cannot find symbol' on attempting following action from jshell: Game game = new Game("shivam");

Error:
cannot find symbol
symbol: class Game
Game game = new Game("shivam");

I tried executing this statement after opening Game.java file from jshell

5 Answers

In your workspace, run the jshell in the console. Type:

treehouse:~/workspace$ jshell

That's open up the REPL - I think you've got this far.

In the repl, open the class:

jshell> /open Game.java

Then you can use your class:

jshell> Game game = new Game("Shivam");

That should work fine.

Steve.

Shivam Barthwal
Shivam Barthwal
2,365 Points

Hi Steve,

I figured out, i was capitalizing char due to which the class game.java was not compiling. now it works fine. I hail your response. it actually gave me clue that i should go back at the root from where i just started, so i tried to compile the class first, that returned with an error pointing out to that particular chunk of code. Many Thanks

Hi there,

This means that it doesn't know what Game is. Have you tried entering load Game first, then trying to use your class?

Steve.

Shivam Barthwal
Shivam Barthwal
2,365 Points

Thank you Steve for your response in a quick time Yea I did so, firstly I opened the Game.java file from jconsole: /open Game.java

I am new to treehouse, trying to figure out how to post code online. I think that would help you better understand the issue. Could you guide me how to post code over here.

  class Game {
  private String answer;
  private String hits;
  private String misses;

  public Game(String answer){
    this.answer = answer;
    hits = "";
    misses = "";
  }

  public boolean applyGuess(Char letter) {
    boolean isHit = answer.indexOf(letter) != -1;
    if (isHit) {
      hits += letter;
    } else {
      misses += letter;
    }
    return isHit;
  }
}
// comment

I'll add some code to your comment - if you click 'edit' you'll see what I did to make it work.

Shivam Barthwal
Shivam Barthwal
2,365 Points

Thanks again, I have inserted the code with Game.java file. Will it help?

OK - so what are you trying to do?

Are you entering your line of code (in the title of this thread) in the workspace console, or the REPL?

Shivam Barthwal
Shivam Barthwal
2,365 Points

I was running this code in the console at bottom of workspace in jshell. I was trying to instantiate Game class by calling constructor from console giving it a value of "Shivam", to which the error occurred, I wanted to check whether the code meets the logic for hits and misses. I would had checked for a letter whether or not it is contained in the value I passed but i got stuck due to error. I was just trying to follow along the instructor

Shivam Barthwal
Shivam Barthwal
2,365 Points

I was running this code in the console at bottom of workspace in jshell. I was trying to instantiate Game class by calling constructor from console giving it a value of "Shivam", to which the error occurred, I wanted to check whether the code meets the logic for hits and misses. I would had checked for a letter whether or not it is contained in the value I passed but i got stuck due to error. I was just trying to follow along the instructor

3 Months later answer but, I don't think you can compile java if your.... // comment ..... is outside the ...... "}"......... block . It will come back in error message and it might show why in the editor . So for future reference put you comments inside your block of CODE. Edit: OKAY I gave bad information ;)

Hi Mark,

Comments within code can go anywhere - they are syntactically irrelevant as they are not interpreted or compiled. They can't cause syntax errors.

Steve.

I got this error because I missed an "}" in my code