File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes errors when trying to compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "errors when trying to compile" Watch "errors when trying to compile" New topic
Author

errors when trying to compile

Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
I am trying to create a program from the Head First Java book. I'm not sure if it was meant to be followed exactly or not. I believe there should be three class files, which I have made and I was able to get on to compile. the other two come back with the same errors.
Here is what I have.
File 1



File 2




File 3, this I was able to compile

I have tried to compile both files 1 and 2. Here are the errors I get with both.

F:\Workspace\Guessgame>javac GuessGame.java
GuessGame.java:2: error: cannot find symbol
Player p1;
^
symbol: class Player
location: class GuessGame
GuessGame.java:3: error: cannot find symbol
Player p2;
^
symbol: class Player
location: class GuessGame
GuessGame.java:4: error: cannot find symbol
Player p3;
^
symbol: class Player
location: class GuessGame
GuessGame.java:7: error: cannot find symbol
p1 = new Player();
^
symbol: class Player
location: class GuessGame
GuessGame.java:8: error: cannot find symbol
p2 = new Player();
^
symbol: class Player
location: class GuessGame
GuessGame.java:9: error: cannot find symbol
p3 = new Player();
^
symbol: class Player
location: class GuessGame
GuessGame.java:30: error: unexpected type
System.out.println("Player one guessed " = guessp1);
^
required: variable
found: value
GuessGame.java:33: error: unexpected type
System.out.println("Player two guessed " = guessp2);
^
required: variable
found: value
8 errors

I have tried everything I can think of, I am very new to this though. I'm quite sure it's something simple I'm doing wrong, or that this example was not meant to actually be run.
Any help will be greatly appreciated.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Remember Java is case-sensitive. Look at the last class.
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
Kieth Thank you.
I see that now and it took care of 6 of the errors. I still have 2 errors I'll post below.
Jeff thank you I will post with the tags from now on. It is definitely easier to read. I'll also start compiling more frequently.

The errors I have now are:
F:\Workspace\Guessgame>javac GuessGame.java
GuessGame.java:30: error: unexpected type
System.out.println("Player one guessed " = guessp1);
^
required: variable
found: value
GuessGame.java:33: error: unexpected type
System.out.println("Player two guessed " = guessp2);
^
required: variable
found: value
2 errors

I see the marker are in the wrong place here. They should be under the first " on each line.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

What exactly do you expect this line to do?



In particular, what do you expect this to do:


That's what you're doing in that line.
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
I also was able to compile the GameLauncher file into a .class file even with the errors.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Tom Rafferty wrote:I also was able to compile the GameLauncher file into a .class file even with the errors.


Then the errors were in one of the other classes. If a given .java file has errors, it will not produce a .class file.
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
I want it to print a line that says, Player one guessed, and the number
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
Okay that makes sense. If you look at the original file, there are 3 lines that are all basically the same. One for each player. They are all the same except for the individual player distinctions yet only 2 come back with an error.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Tom Rafferty wrote:I want it to print a line that says, Player one guessed, and the number


That is a simple case of printing concatenated Strings. Think how will you print it. How do you print a variable value using system.out.println()? Say, if I have a variable int a = 10, how will you print "The value of a is 10"?


~ Mansukh
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
System.out.println("Tom Rafferty");
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Tom Rafferty wrote:System.out.println("Tom Rafferty");


Are you sure you need to hard code your name?
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
I see it now. I have a = where it should be a +. Thank you for all your help. It is working fine now.
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
If I set my name to a variable I could just print the variable.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

I am of the opinion that you are attempting to do a lot of things in one go. If you are new to the language, get you basics crystal clear. That is the first thing I believe one should do. What are the topics that you have already covered and what chapter are you on currently?
Tom Rafferty
Greenhorn

Joined: Apr 16, 2013
Posts: 11
I am trying to learn this on my own. I come from a networking background, with very little coding experience, a little HTML and Basic language. I am on chapter 2 classes and objects. As I said originally this may not be an example I was meant to work with.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

OK. Try and grasp the concepts. Come back with doubts. Always happy to guide. Start with smaller examples, get them working, understand how things work. It is pretty amazing how things work.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Supun Lakshan Dissanayake, please do not post replies that merely repeat what's already been covered.

Thanks!
Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 132

Jeff Verdegan wrote:Supun Lakshan Dissanayake, please do not post replies that merely repeat what's already been covered.

Thanks!


Sorry I didn't meant to do it. but google chrome browser does NOT show my post.
So i thought something jammed and i repost it.

Anyway thanks for point out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: errors when trying to compile