• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head First Java BeatBox, wont compile!  RSS feed

 
Henrik Persson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

I am totally new to programming in every way, shape or form, and I'm working my way through the Head First Java book (2nd ed). I have just finished copying the code for the initial BeatBox app, the one starting on page 420.
When I try to compile it, I get these errors:



There's obviously something wrong with the Box class but I can't seem to figure out just what it is. I checked the API and the Box constructor is supposed to take an int argument for its axis, but the compiler doesn't seem to identify BorderLayout.Y_AXIS as an int. Later on it thinks that BorderLayout.EAST and BorderLayout.WEST are Strings, and I don't know maybe they are, but it looks weird...

Here is my code for the buildGui() method, where all the errors live:


I doubt that this is relevant, but I'm running Mac OS X, coding in TextWrangler and compiling with Terminal. Java version is 1.6.0_24.

I apologize in advance if I've made an obvious mistake, but I've checked the code quite a few times and it looks right to me at least...
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are 2 primary errors, and the rest you show are a result of those. The compiler is trying to find your class Box and its constructor, Box(). I don't have the book to check what you've done wrong, but there's something you're not including. Either you haven't imported the Box class or included it as another part of the same project. Refer to the book, find the Box class, figure out how it was supposed to be included as a part of this exercise, and include it.
 
Kurt Van Etten
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henrik,

Welcome to the Ranch! Just to repeat what Greg said, for some reason the Box class isn't being imported. Check your import statements and make sure it's there (or that you're importing all of javax.swing.*), and that ought to take care of the Box errors.

[Edit: deleted some nonsense I said after the above...]
 
Henrik Persson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out what was wrong. Last week I wrote a class that drew boxes based on user input, and of course I named it "Box". Renamed it, and BeatBox compiles just fine now. Can't hear any sound though... back to work.

Thank you all for replying!
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again.

If you are that new I would suggest you try something simpler than the beat box exercise at first.
 
Henrik Persson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch again.

If you are that new I would suggest you try something simpler than the beat box exercise at first.

Well I am new, but I've worked my way through the book and done all the exercises so I'm definitely ready for it. It just so happened that I created a class with the same name as one that already existed in the API and was needed in the BeatBox exercise, and had it in the same folder.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have worked through the whole book as far as beat box you are not "totally new" any more
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!