petit probleme avec Vector
Bonjour,
j'etais entrain de faire un petit exercice sur les exception.
Lorsque je compile tout vas bien mais lorsque j'excute ca m'affiche un message d'erreur " ArrayIndexOutOfBoundsException ".J'ai beaucoup essaier de trouver ou se trouve ce depassement de taile du tableau mais je ne suis pas arrivé à le localisé.
Merci beaucoup pour votre aide à l'avance.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class TestEtudiantBis {
public static void main(String[] a){
String[] args={"Yassine", "19", "18", "19", "Coq", "5", "9", "8", "7", "1", "Ghassen", "12", "13", "16"};
Vector v = new Vector();
int x=0;
for(int i=0; i<args.length; i++){
try{((Etudiant) v.elementAt(x)).entrerNote(Integer.parseInt(args[i]));}
catch (NumberFormatException e){v.addElement(new Etudiant(args[i])); x++;}
catch (TabNotesPleinException e){System.out.println(e.getMessage()+" pour l'etudiant "+args[i]);}
}
for(int i=0; i<v.size(); i++){
((Etudiant) v.elementAt(i)).toString();
}
}
} |
le message d'erreur à l'execution :
Code:
1 2 3 4
|
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:431)
at TestEtudiantBis.main(TestEtudiantBis.java:42) |
la ligne indiqué par les message d'erreur est celle ou se trouve " try { "