• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with iterators

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I've been reading the Head First Design Patterns book and i've stumbled upon a problem. On the chapter about the iterators, i tried typing and compiling the code that the book gives, but i cant get it to compile.



Specifically I'm getting an error on: return new PancakeHouseMenuIterator(menuItems); this line in the end.
.\PancakeHouseMenu.java:26: cannot find symbol
symbol : constructor PancakeHouseMenuIterator(java.util.ArrayList<MenuItem>)
location: class PancakeHouseMenuIterator
return new PancakeHouseMenuIterator(menuItems);

Could somebody help me out with this one? I don't see what is wrong with it. By the way here's the PancakeHouseMenuIterator class, since i think it is pretty useful to help me resolving this problem.



If you need anything else please let me know, thanks in advance.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the keyword void on line 8 in PancakeHouseMenuIterator is causing the problem. Try removing that.

Hutner
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am surprised to see that hasNext() method. It is bad style to write if (...) return true; else return false; or similar. It would have been better written it like this
 
Ugluth Papadopoulos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did try what you suggested, removing the void keyword from PancakeHouseIterator but then i get: PancakeHouseMenuIterator.java:8: invalid method declaration; return type required

Actually, I entered the void there, since I got this error, but i guess problems aren't that straightforward. About the other suggestion thank you, I didn't really put much thought in it, these examples are from the book, head first design patterns, so i just copied the code.

Any other suggestions about what might be wrong?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry didnt notice that the method signature was for PancakeHouseIterator not PancakeHouseMenuIterator.

change it to this:


If this is directly from the book, I'm surprised they missed this error.

Hunter
 
Ugluth Papadopoulos
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nop they didn't miss it, even though with the new version you do have to add the <MenuItem> on the ArrayList, since it was not needed for java 5 on which the book was published i think. But it was a typo error after all, instead of PancakeHouseMenuIterator I had PancakeHouseIterator...

God i hate when i look for a solution to such a problem for a long time Anyway, thank you very much for your input, greatly appreciated

Cheers!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic