Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find symbol - method iterator()

 
Emanuel Mensa
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, can someone please help me with this error i get at compile time?

here's my code:


 
Winston Gutkowski
Bartender
Pie
Posts: 10492
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10492
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much Campbell Ritchie!!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic