• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stuck in headfirst Java chapter 4  RSS feed

 
Cody Prince
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm using the headfirst java book, and just picked it up again after a while away. I typed out the following excercise and got the following errors, can someone please explain to me how to remedy these errors so I can continue?
Code:

Error:
GoodDog.java:6: error: <identifier> expected
Public void setSize (int s) {
^
GoodDog.java:6: error: invalid method declaration; return type required
Public void setSize (int s) {
^
GoodDog.java:12: error: unclosed string literal
System.out.println("Woof, Woof!);
^
GoodDog.java:12: error: ';' expected
System.out.println("Woof, Woof!);
^
GoodDog.java:14: error: unclosed string literal
System.out.println("Ruff, Ruff!);
^
GoodDog.java:14: error: ';' expected
System.out.println("Ruff, Ruff!);
^
GoodDog.java:15: error: not a statement
} else (size > 14) {
^
GoodDog.java:15: error: ';' expected
} else (size > 14) {
^
GoodDog.java:15: error: 'else' without 'if'
} else (size > 14) {
^
GoodDog.java:16: error: unclosed string literal
System.out.println("Yip, Yip!);
^
GoodDog.java:16: error: ';' expected
System.out.println("Yip, Yip!);
^
GoodDog.java:13: error: 'else' without 'if'
} else if (size > 14) {
^
GoodDog.java:19: error: reached end of file while parsing
}
^
13 errors
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cody Prince wrote:Hi, I'm using the headfirst java book, and just picked it up again after a while away. I typed out the following excercise and got the following errors, can someone please explain to me how to remedy these errors so I can continue?
Code:

Error:
GoodDog.java:6: error: <identifier> expected
Public void setSize (int s) {
^
GoodDog.java:6: error: invalid method declaration; return type required
Public void setSize (int s) {


I will help with the first two problems, the rest you should be able to solve by reading the error messages. But for these, the key thing to remember is that Java is case sensitive. Do you see the mistake you made on that line: Public void setSize(int s) {? If you fix that then both the first two errors will go away I think.
 
Cody Prince
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did resolve my first two errors, but its still giving me the missing semi colon errors when there is semi colons at the end of the method. Can you explain what I need to do to remedy that? Also I'm getting an else with out if error, but in the book its word for word so I', also lost on that
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cody Prince wrote:Also I'm getting an else with out if error, but in the book its word for word so I', also lost on that

Are you sure ? I believe there are some examples in the book that don't compile - they are intended to demonstrate errors, but your code looks really strange. All your conditions are identical (size > 14).
But anyway, that error indicates there is a missing if on line 15 - compare it to line 13. The error about the missing ; is probably a side effect of one of the other errors. Fix the unclosed string literal errors and it may just disappear.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!