IntelliJ Java IDE
The moose likes Bunkhouse Porch and the fly likes Another error in the book? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Books and Education » Bunkhouse Porch
Reply Bookmark "Another error in the book?" Watch "Another error in the book?" New topic
Author

Another error in the book?

Aaron Kulbe
Greenhorn

Joined: Jun 14, 2004
Posts: 2
I'm not sure if this is the case... but I'm having trouble with the very first set of code in the "Head First Java" book.

----------------------------------------------------
import java.awt.*;

import java.awt.event.*;

class Party {

public void buildInvite() {

Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Shoot me")
Panel p = new Panel();
p.add(l);
} // more code...


--------------------------------------------------

that's how I have the code typed out. That's EXACTLY how it appears to me in the book. With the left-out semi-colon on the end of the Button c line, and with an l (el) in the p.add line.

I get compile errors with this, as follows:

bash-2.05b$ javac Party.java
Party.java:12: ';' expected
Button c = new Button("Shoot me")
^
Party.java:15: '}' expected
} // more code...
^
Party.java:10: cannot resolve symbol
symbol : class Level
location: class Party
Label l = new Level("Party at Tim's");
^
Party.java:14: cannot resolve symbol
symbol : variable p
location: class Party
p.add(1);
^
4 errors
bash-2.05b$

That's have it typed out. what gives?
Sudheer Reddy
Greenhorn

Joined: Jun 16, 2004
Posts: 1
hai,
Don't put book printing mistake errors into Forum.Better u ask any java genuine errors.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 23395

Hi Aaron,

Welcome to JavaRanch!

Indeed, this does look like a typo in the book. The best place to discuss book issues is in our Bunkhouse Porch forum. I'm going to move this post there for followup.

Note that this book, like many books, has a web page listing printing errors. It's a good idea to check this list.


[Jess in Action][AskingGoodQuestions]
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4011
Now that's a sight, actual *code* on the Bunkhouse Porch.

Looks like there are a few typos in there Aaron, so you probably will find them on the errata list for this book. I'm having trouble locating where that code is exactly in the book (I suspect it's way beyond the very first code), but with the page numbers you should have no problem.

The compiler is crying out to help you fix them too, of course. That missing ; on line 12, then a right curly bracket on line 15 to match the opening class bracket, those are the nice errors (that is, easy to fix ).

The next one confuses me a bit, though. The error says that the compiler is looking for a class called Level, from line 10:

Label l = new Level("Party at Tim's");

Yet the code you give above

Label l = new Label("Party at Tim's"); // Label, not Level

doesn't quite look the same, and probably wouldn't give that error.

....

Anyway, after addding a closing curly bracket and a semicolon, the code as follows compiled fine for me:


Simple compiler errors can induce other, more mysterious ones - fixing those syntax mistakes first sometimes clears up those later errors too.


Like Ernest said, welcome to the ranch and hope you'll be visiting often. And enjoy Head First Java


Pauline
[ June 18, 2004: Message edited by: Pauline McNamara ]
 
IntelliJ Java IDE
 
subject: Another error in the book?
 
Threads others viewed
extreme newbie question
New In Java need a little help please
Party.java in HeadFirst Java p. 3
beginner's question
class-file not executing
IntelliJ Java IDE