Enumeration pour Parcourir Hashtable
Bonjour,
Je souhaite parcourrir ma Hashtable mais je n'y arrive pas
ma classe : Roman
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
public class Roman {
/** Creates a new instance of Roman */
private String nomR;
private int noIsbR;
public Roman(String n, int i) {
this.nomR = n;
this.noIsbR = i;
}
public void setNomTitre(String n){
this.nomR = n;
}
public void setNoIsbn(int i){
this.noIsbR = i;
}
public String getNomTitre(){
return(this.nomR);
}
} |
Le main :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
import java.util.*;
...
public static void main(String[] args) {
Hashtable maTable;
maTable = new Hashtable();
Roman livre = new Roman("A l'ouest...", 1);
maTable.put(1, livre);
livre = new Roman("A l'Est...", 2);
maTable.put(2, livre);
for (Enumeration e = maTable.keys(); e.hasMoreElements();){
System.out.println(((Roman)e.nextElement()).getNomTitre()); //ligne erreur 41 |
Erreur :
Exception in thread "main" java.lang.ClassCastException: java.lang.Integer
at applihashtable.Main.main(Main.java:41)
Je pense que je fais un mauvais transtypage
Merci de votre aide