Raul Quinzani Raul Quinzani - 2 years ago 81
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

Answer Source

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

lista.add(new ArrayList<Cadeira>());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download