Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes cannot find symbol - method iterator() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot find symbol - method iterator()" Watch "cannot find symbol - method iterator()" New topic
Author

cannot find symbol - method iterator()

Emanuel Mensa
Ranch Hand

Joined: Feb 22, 2013
Posts: 31
hello, can someone please help me with this error i get at compile time?

here's my code:


Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8043
    
  22

lalapnt pinto wrote:here's my code:...

lalapnt,

Please DontWriteLongLines (←click). I've broken yours up this time, but it makes your thread very hard to read.

Oh, and welcome to JavaRanch.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

You're calling iterator() on an array. Collection classes have that method, but arrays don't (see http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.7 for the members that arrays have).

If you want to iterate over an array you can either use a normal for loop with an index, or you can use the enhanced for loop. If you don't need the index I'd use the latter.
Emanuel Mensa
Ranch Hand

Joined: Feb 22, 2013
Posts: 31
oh! i see hehe thank you very much @Matthew Brown

and thanks for the caution @Winston Gutkowski. are you from Poland? just btw
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8043
    
  22

lalapnt pinto wrote:and thanks for the caution @Winston Gutkowski. are you from Poland?

Nah. My father. I've been a few times, but I'm afraid I don't know much more than dzień dobry, prosze and dziękuje.

I do love flaczki though.

Winston
Emanuel Mensa
Ranch Hand

Joined: Feb 22, 2013
Posts: 31
Winston Gutkowski wrote:
lalapnt pinto wrote:and thanks for the caution @Winston Gutkowski. are you from Poland?

Nah. My father. I've been a few times, but I'm afraid I don't know much more than dzień dobry, prosze and dziękuje.

I do love flaczki though.

Winston


ok great . nice meeting you. i live and study in Poland.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Never write == true or similar. It is poor style and error‑prone; you might write = by mistake.
Not
if (b == true) ... or if (b == false) ...
Write:-
if (b) ... or if (!b) ...
Emanuel Mensa
Ranch Hand

Joined: Feb 22, 2013
Posts: 31
Campbell Ritchie wrote:Never write == true or similar. It is poor style and error‑prone; you might write = by mistake.
Not
if (b == true) ... or if (b == false) ...
Write:-
if (b) ... or if (!b) ...


ok thank you very much. something new learned.

so assuming my boolean is defined. and i believe all declared booleans have a default value "false"

so i can write



is that what you mean?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
lalapnt pinto wrote: . . . i believe all declared booleans have a default value "false"
Only fields have default values; local variables do not, so that would be a compiler error unless you have previously said something like check = false;
It is poor style to use the default values of fields; they should be explicitly initialised:-
so i can write



is that what you mean?
Yes, provided the boolean actually has a value.
Emanuel Mensa
Ranch Hand

Joined: Feb 22, 2013
Posts: 31
thank you very much Campbell Ritchie!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
You’re welcome
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: cannot find symbol - method iterator()