• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Head First java chap 5 doesn't compile  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm starting to learn Java with the Head First Java book (my manager at work gave me the book), but I get stuck at chapter 5.
I write the code in Notepad++ and compile it in commandprompt.
I'm supposed to write the code for two classes, and copy the code for the third class. I can also copy the code for all three classes, leaving me with the same error.
The error: Could not find or load main class SimpleDotCom
Could not find or load main class Game
Could not find or load main class GameHelper

The code is in three different files.
The code:








Can someone please help me out?
 
Ranch Hand
Posts: 185
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The GameHelper class is in the chap5 package and not in the helpers package. That's why you are getting the error. Comment out the import helpers.GameHelper and see what happens
 
Marshal
Posts: 5633
147
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch! Thank you for using code tags and formatting your code.

What command are you using on the command line and what directory are you in when you issue it? Remember that you have to be cd'd to the project root and using the "dot" name for the Java file.
 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note also that the class referenced on the commandllne needs to have a main() method for the java program to find to start the program's execution.
Game is the only class I see with a main method.
So the command would be: java chap05.Game
 
Nicole Munneke
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies, sadly, it still doesn't work.
When trying to compile the Game.java (javac Game.java), I get the following errors:

Game.java:11: error: cannot find symbol
GameHelper helper = new GameHelper();
^
symbol: class GameHelper
location: class Game

Game.java:11: error: cannot find symbol
GameHelper helper = new GameHelper();
^
symbol: class GameHelper
location: class Game

Game.java:13: error: cannot find symbol
SimpleDotCom theDotCom = new SimpleDotCom();
^
symbol: class SimpleDotCom
location: class Game

Game.java:13: error: cannot find symbol
SimpleDotCom theDotCom = new SimpleDotCom();
^
symbol: class SimpleDotCom
location: class Game



I did comment out the import helper.GameHelper, and got these errors when I tried to recompile it into a .class.



I also tried to work with chap05.Game.java, but that doesn't seem to do the trick, because I get the error it can't find the file, or it can not find or load the main class.
 
Rancher
Posts: 3797
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are in the directory that contains the chap05 directory then the compilation command should be:
javac chap05/Game.java

You use the file path, not dot notation.
That assumes you haven't set a CLASSPATH environment variable (which you shouldn't have done).

If you were in the chap05 directory then you would have to tell javac where the package root is:
javac -cp.. Game.java

That tells javac to use the directory above the one you are in as the classpath.
 
Don't MAKE me come back there with this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!