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
posted
0
hai, Don't put book printing mistake errors into Forum.Better u ask any java genuine errors.
Ernest Friedman-Hill
author and iconoclast
Marshal
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.
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