Raul Quinzani Raul Quinzani - 4 months ago 5x
Java Question

add Objects in a bidemensional arrayList of size unknow JAVA

i'm trying to add a element in an arrayList that is inside a arraylist,
when i had elements before i used to get a element by putting


and it returns to me whatever is inside this coordenates

i'm trying to add objects while my biArrayList is empty, so i have this:

private List<List<Cadeira>> lista = new ArrayList<List<Cadeira>>();

however i'm getting in a exception because my position 0 does not exist yet

any ideia on how to solve this??
ty in advance


You need to initialize the list first with a constructor. Do

lista.add(new ArrayList<Cadeira>());