So I have written a for loop that will go through my arraylist and should check if the value is empty. When it finds an empty arraylist value it will add the new vertex. So far it is like this:
for(int i = 0; i < Vertices.size()+1; i++){ if(Vertices.isEmpty()){ Vertices.add(i); break; } if(Vertices.get(i) == null){ <------------------------------------------------------ Display.append(" Vertices " + Vertices.get(i+1) + " added" + newline); Vertices.add(i); break; } else{ System.out.println("Nothing"); } }
So it will check if the arraylist is empty, if it isn't it will check if the value at position 'i' in the arraylist is null. If it isn't null it will add 1 to 'i' and try again until it finds a null value. The problem is with the line that checks if the value is null but I don't know why that is wrong or how to fix it.
The problem is that I am getting an exception when it tries to add the second vertex