Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

errors when trying to compile

 
Tom Rafferty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember Java is case-sensitive. Look at the last class.
 
Tom Rafferty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also was able to compile the GameLauncher file into a .class file even with the errors.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want it to print a line that says, Player one guessed, and the number
 
Tom Rafferty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"?
 
Tom Rafferty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println("Tom Rafferty");
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Rafferty wrote:System.out.println("Tom Rafferty");


Are you sure you need to hard code your name?
 
Tom Rafferty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I set my name to a variable I could just print the variable.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supun Lakshan Dissanayake, please do not post replies that merely repeat what's already been covered.

Thanks!
 
Supun Lakshan Dissanayake
Ranch Hand
Posts: 135
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic