Problème avec Vector et Iterator
Bonsoir à tous,
Je suis désespéré car je n'arrive pas à récupérer l'élément d'un vecteur. Voici mon code Main :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package projet4ig;
import javax.swing.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
int test=0;
Etudiant p1 = new Etudiant("Jean","Michel");
p1.choixstu.add("Alcatel");
p1.choixstu.add("Alstom");
Entreprise e1 = new Entreprise("Alstom");
e1.choixsoc.add("Jean");
e1.choixsoc.add("Michel");
while (p1.stu.hasNext())
{
System.out.println(p1.stu.next());
}
}
} |
Voici maintenant le code de la classe Etudiant (la classe entreprise est construite sous le même modèle) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| package projet4ig;
import javax.swing.*;
import java.util.*;
public class Etudiant {
private String nom;
private String prenom;
Vector choixstu = new Vector();
Iterator stu = choixstu.iterator();
public Etudiant(String nom1,String prenom1)
{
nom=nom1;
prenom=prenom1;
}
public Vector getchoix()
{
return choixstu;
}
public String getnom()
{
return nom;
}
public String getprenom()
{
return prenom;
}
} |
Quand je compile le code, il me met une exception :
Code:
1 2 3 4 5
| 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 projet4ig.Main.main(Main.java:42)
Java Result: 1 |
Apparemment cela serait un problème dû au Next() mais si je retire cette ligne de code et que j'affiche une variable dans la boucle while(), il me l'affiche indéfiniment...alors que mon vecteur n'est pas rempli...je ne comprends pas du tout...