File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner classes in Eclipse

 
Liz Carter
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am half way in Head first java.. and trying out the pool puzzle on page 396. for the amazing shrinking blue rectangle.

I am using eclipse to complie and run my programs. but it doesnt seem to recognize the inner class MyDrawP. I am getting the error MyDrawP cannot be resolved to a type. Please let me know where I am making the mistake?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will be quicker to help you if you post the code.
 
Liz Carter
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here goes...
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I have enclosed your source with a "code" tag. Please use it the next time you post some code.)

You have declared the inner class inside a method. I don't know how the code looks in your book, but if you want to use an inner class that way, you'll have to declare the class before using variables of that class. Like this :


Are you sure that the MyDrawP class is inside the go() method ?
 
Liz Carter
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declaring the inner class before the variables removed the error. Thanks.

and yes the inner class is declared in go() and it is given at the end of the method in the book.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the book didn't declare the class just after the method, instead of at the end inside?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic