sunrisepoet sunrisepoet - 9 months ago 56
Java Question

ArrayList throwing syntax error "Unknown class"

Doing some tutorials on java this simple foreach loop on a list is giving me an error in the foreach loop: "Unknown class: familyMembers". I dont see where the problem is. but i know is something simple. Thanks in advance.

Update: I have all the imports necessary.

List<String> familyMembers = new ArrayList<String>();


for (String name : familyMembers){

Answer Source

it looks like familyMembers is a method-locally declared variable

the for loop must be implemented in a method where the familyMembers can be access or scope