• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Cannot find symbol" error at compiling  RSS feed

 
Jane Jacobsen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there! I'm new to java and I'm currently learning from the book Head First Java. There is a guessing game example, with three different classes, all of which I've saved in different java files, with the names GameLauncher, GuessGame, and Player. I can only compile the last one, however.

Code in the GameLauncher.java file:



I get the following error:


As for the GuessGame.java file, here's the content:



I get exactly the same error as before, but the "word" in cause is Player. I first thought of the fact that java is case sensitive, but I seem to have typed it with a capital P every time (the .java file begins with a capital P and the name of the class inside is also capitalized). So is the case with GuessGame. There may be typos that I haven't noticed, though. Any help would be greatly appreciated.

P.S. If needed, here is the code in the Player file, as well:


 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably don't want to be compiling in the /bin directory. you don't want to mix up your .class files with what come as part of the java install.

The good news is that your code is all correct. I just compiled and ran it without issue. Your issue is that java doesn't know where your .class files are, so when you try to compile the later ones, it doesn't know what you are referring to.

Do you know if you have a CLASSPATH environment variable set? You don't need one (at least at this stage). Note that this is different from a PATH variable. Don't mess with the PATH unless you know for sure what you are doing.

 
Jane Jacobsen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not know how to run the command javac in a different directory, since I get the "javac is not recognized as an internal or external command" error. I did add my bin folder to the PATH environment variable. After compilation, my class files are saved in the same folder as the initial java files. I had no such problems before, probably because this is my first time using multiple files and classes related to one another. I could find no CLASSPATH variable set, so I suppose I don't have one (?)
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using the same cmd window before and after editing the PATH, it doesn't pick up the change. You need to open a new cmd window after editing/saving the PATH.

BTW, the PATH should contain the directory where the javac.exe lives...from your screenshot, that should include "C:\Program Files\Java\jdk.7.0_25\bin". you can see what any open cmd window has set by typing "echo %PATH%" (or really ANY environment variable between '%' signs).

Most folk around here would recommend you don't set the CLASSPATH. If you don't see one, then no, you probably don't have it set.
 
Jane Jacobsen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your advice. It works now (though I couldn't tell exactly why), I just played around a bit (re-adding the bin folder to path, moving the .java to-be-compiled files to a different folder, etc.).
Glad I can simply type the javac command now, without having to navigate back and forth between directories. Solved!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!