This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Rock, paper scissors error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Rock, paper scissors error" Watch "Rock, paper scissors error" New topic
Author

Rock, paper scissors error

Sara Bear
Greenhorn

Joined: Nov 05, 2012
Posts: 8



can not figure out how to fix the illegal start of expression for my playerAnswer function. Anybody have any ideas for me?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hi, and welcome to the Ranch!

When posting code please UseCodeTags(←click) so it will be readable. I've added them for you here.

Also, both when editing your code on your computer and when posting here, use spaces for indenting, not tabs. That will improve readability. I've done that for you here too.

Compiler errors are usually pretty direct and clear about exactly what's going wrong, but "Illegal start of expression" is a trickier one. It means the compiler has gotten confused as to where in the program it is (as opposed to something simpler like "I know I'm reading the name of a method you're calling, but there is no such method"). Usually because of missing or extra braces. In this case, it's seeing the declaration for your playerAnswer() method and saying, "This doesn't belong here." The reason is, if you look right above that, you'll see that you didn't put a close brace at the end of your main() method. I don't know if that was just an oversight or if you were trying to define one method inside another, but you can't do that.

So next time you see that error message, double check your braces!
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 245
i see random not declared propery and no implementation for method getwinner();
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

If you're getting more errors and you can't figure them out after reading the error messages very closely and carefully and looking closely and carefully at the lines they're complaining about, then please post your current code, copy/paste the exact, complete error messages, and indicate clearly which lines are causing them.
Sara Bear
Greenhorn

Joined: Nov 05, 2012
Posts: 8



RockPaperScissors.java:43: error: invalid method declaration; return type requir
ed
getwinner(player, computer)
^
RockPaperScissors.java:43: error: <identifier> expected
getwinner(player, computer)
^
RockPaperScissors.java:43: error: <identifier> expected
getwinner(player, computer)
^
RockPaperScissors.java:58: error: illegal start of type
while (player == computer)
^
RockPaperScissors.java:58: error: <identifier> expected
while (player == computer)
^
RockPaperScissors.java:58: error: ';' expected
while (player == computer)
^
RockPaperScissors.java:58: error: illegal start of type
while (player == computer)
^
RockPaperScissors.java:59: error: ';' expected
System.out.print("Tie, Please select again);
^
RockPaperScissors.java:59: error: <identifier> expected
System.out.print("Tie, Please select again);
^
RockPaperScissors.java:59: error: unclosed string literal
System.out.print("Tie, Please select again);
^
RockPaperScissors.java:70: error: reached end of file while parsing
11 errors



Then I am supposed to validate case-insensitve player answers. cannot even think that far ahead!
Sara Bear
Greenhorn

Joined: Nov 05, 2012
Posts: 8
sai rama krishna wrote:i see random not declared propery and no implementation for method getwinner();


I am not even sure what that means.......
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You have this:



At the line I've labeled #1, you are declaring the method computerRandom(). You are properly indicating its return type (String) and you also give some additional information--you state that it's public and static. In the following lines, you provide that method's body.

At #2, the close brace ends that method. You should put a blank line after that.

At #3, thought it's harder to see without the blank line, it looks like you're declaring another method called getwinner(). But you didn't indicate a return type. That's why it's giving you the method "return type required" for that line.

Also, you should use camel case: getWinner, rather than getwinner. That's not an error, but if you follow conventions it will be easier for others to understand your code.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Sara Bear wrote:
sai rama krishna wrote:i see random not declared propery and no implementation for method getwinner();


I am not even sure what that means.......


You have this:

What type is the "random" variable? You haven't declared it.
Aj Prieto
Ranch Hand

Joined: Sep 28, 2012
Posts: 72

Also in your print statment in your while loop, your missing a " at the end of the sentence.


Da mihi sis bubulae frustum assae, solana tuberosa in modo Gallico fricta ac quassum lactatum coagulatum crassum.
 
jQuery in Action, 2nd edition
 
subject: Rock, paper scissors error