I have a program that reads from a txt file line by line splits up the string and puts it in to an arraylist
while ((inputLine2 = infile2.readLine() )!= null)
{
//string to split up
String[] programData = inputLine2.split(":");
List<CoursesInProgram> programContents = new ArrayList(programContents);
//constructor
programContents.add(new CoursesInProgram(programData[2],programData[3],
programData[4],programData[5],programData[6],programData[7],
programData[8],programData[9]));
//other constructor
programlist.add
(new Program(programData[0],programData[1], programContents));
}
And I get the error The local variable programContents may not have been initialized. Reading here I learned that happens when eclipse thinks that it possible i’ll never enter the loop.
so I changed it to a do while loop and still had the same problem.
then i tried to initialize the array outside the loop and i got a duplicate variable error.
what do you think is the solution?
List<CoursesInProgram> programContents = new ArrayList(programContents): the variableprogramContentsappears twice here; what do you expect to happen?