I am trying to create a multidimensional arraylist. but it is not adding this is my code
here is the initialization
public class BinList {
private ArrayList<Garbage> GarbageList;
private int[] PenaltyArray = new int[10];
private ArrayList BoostList;
this is the constructor
public BinList() {
BoostList = new ArrayList<Integer>();
}
this is the method, this method takes two parameters the first is the file path and the second is a loop from 1 to 10. so i read the file and send the information of each line with the loop number to another method to create the arraylist (ArrayList) and it works fine so when this method is done and all the file is read i insert the arraylist(ArrayList) into the arraylist(ArrayList BoostList) but there is no new values in this arraylist. am i doing something wrong here? if anymore code is needed please tell me
public void ReadLine(String filePath, int Container) {
try {
File file = new File(filePath);
Scanner scan = new Scanner(file);
GarbageList = new ArrayList<Garbage>();
while (scan.hasNextLine()) {
String readLine = scan.nextLine();
if (readLine != null) {
getSplitLinesOrders(readLine, Container);
}
}
((ArrayList) BoostList.get(Container)).add(GarbageList);
} catch (Exception e) {
}
}
You are trying to get an ArrayList from BoostList:
but you never add anything to BoostList, so this will always fail.
You catch Exceptions but swallow them silently (you don’t print an error) so this problem is hidden.