So I've made a multi-dimensional array lists where surnames, forenames, email.. etc should be stored and it reads this information form a .txt file. There seems to be an index out of bounds error popping up and I dont know what for.
public static void readFilesIntoArrayLists(String filename) throws IOException
{
Scanner in;
int i = 0;
in = new Scanner(filename);
String [] fileElements;
mainList = new ArrayList<ArrayList<String>>();
mainList.add(new ArrayList<String>());
mainList.add(new ArrayList<String>());
mainList.add(new ArrayList<String>());
mainList.add(new ArrayList<String>());
mainList.add(new ArrayList<String>());
while(in.hasNext())
{
fileElements = (in.nextLine().split(","));
mainList.get(0).add(fileElements[0]);
mainList.get(1).add(fileElements[1]);
mainList.get(2).add(fileElements[2]);
mainList.get(3).add(fileElements[3]);
mainList.get(4).add(fileElements[4]);
}
in.close();
System.out.println("Files have been read..");
}
fileElementshas at least 5 elements on each line? the error is probably coming from there