I'm still very new to java. I am trying to create an array of objects from a text file. The text file has a list of names, and using these names, I'm trying to create objects. This is the method I've created to create the objects from the text file input. It gives an error when compiled. I'm not sure where I've done wrong.
public boolean createObjects(PersonNames2[] person) throws Exception
{
boolean found = false;
int position = 0;
if(canCreateObjects() == true)
{
for(int i = 0; i < persons.length && !found; i++)
{
if(persons[i] == null)
{
position = i;
found = true;
}
}
Scanner reader = new Scanner(file);
while(reader.hasNext())
{
person[position] = new PersonNames2();
position++;
}
reader.close();
return true;
}
return false;
}
personand your are usingpersons