Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2008, 14:41
tunombre
 
Fecha de Ingreso: enero-2008
Mensajes: 10
Antigüedad: 16 años, 4 meses
Puntos: 1
Pregunta Problema eliminando elemento de un ArrayList

Bien el caso es el siguiente:

Tengo un declarado: private ArrayList <Coche> listadoCoches = new ArrayList();

Y este método que elimina un coche del ArrayList siempre que coincida la matricula

Código:
23       public void sacaCoche(String matricula)
24	{
25		Coche cocheABorrar = null;
26
27		for(Coche coche:listadoCoches)
28		{
29			if(coche.getMatricula().equalsIgnoreCase(matricula))
30			{
31				cocheABorrar = coche;
32				break;
33			}
34		}
35		if( cocheABorrar == null )
36			System.out.println("Coche no encontrado");
37		else this.listadoCoches.remove(cocheABorrar);		
38	}
Cuando lo ejecuto pasandole una matrícula existente en el Arraylist me devuelve esto:

Código:
Exception in thread "main" java.util.ConcurrentModificationException
        at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
        at java.util.AbstractList$Itr.next(AbstractList.java:343)
        at boletin2.ejercicio7.Concesionario.sacaCoche(Concesionario.java:26)
        at boletin2.ejercicio7.Prueba.main(Prueba.java:40)
Java Result: 1
Según entiendo tiene que ver con el Iterator implicito en el bucle pero no entiendo bien cuál es el problema.


Gracias