• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot run Quiz Card app source code from Head First Java  RSS feed

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.I've downloaded the source code for a Quiz Card app from the Head First Java book but I can't get It to run.I receive a cannot find symbol (QuizCard) error.The QuizCard class files are present.
Another thing that confuses me Is that both the QuizCardBuider and QuizCardReader have <public static void main> methods which ,as I understood,can only exist In one of the package classes.

I would appreciate any assistance !

QuizCard




QuizBuilder



QuizReader








 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I added code tags, which you should always use, and see how much better it looks now

Did you realise that the code downloaded and the code in the book are different; is it page 450? There is a line at the beginning saying package chap14;. So the .class files should be inside a directory with the same name as the package. And the class is not called QuizCard. It is called chap14.QuizCard. Read about packages in the Java Tutorials.

Simple solution: create a directory with the right name:-
mkdir chap14
Move all your QuizXXX.java files into that chap14 directory. Do not use cd or similar on the command line.
Compile all the files with
javac chap14/*.java
Run them with this instruction or similar:-
java chap14.QuizCardReader
You will find out there are other ways of achieving the same outcome.
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have a main method in every class if you wish. Some people write main methods in every class in order to run tests on that class. I suspect there are actually two applications in that chapter, but I haven't read them well enough to be sure.
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sheriff! Much obliged
 
Campbell Ritchie
Marshal
Posts: 56581
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome I presume you got it to work like that?
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep.You'd be right!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!