Hi, im using arraylist to store a collection of objects. I have a menu that do a lot of things, also loading/saving. Saving works well, and loading too, but im having a hard time trying to copy the loaded collection in the actual one, because i get IndexOutOfBoundsException in the collection, when calling collections.copy.
Here is the code. I translate and coment each thing:Code:public void cargarRacionals() {
ObtenirRacional or = new ObtenirRacional();
System.out.println("XX:" + (or.retornarRacionals().size()));
//racionals.ensureCapacity((or.retornarRacionals().size()));
ArrayList<Racional> racionals = new ArrayList<Racional>(or.retornarRacionals().size()+1);
Collections.copy(racionals, or.retornarRacionals());
}
racionals : the arraylist of racional objects.
ObtenirRacional :the class that loads and deserializes.
retornar racionals: return the array
Ok. The error is in the last line, and i dont get why. I have tried with the two ways:
//racionals.ensureCapacity((or.retornarRacionals().s ize()));
ArrayList<Racional> racionals = new ArrayList<Racional>(or.retornarRacionals().size()+ 1);
I create a new array with the needed size, or i set the new size. Note that size is ok, its says its 8 and it goes well.
pd: sorry for my bad english

