Bonjour,
Je souhaite parcourrir ma Hashtable mais je n'y arrive pas
ma classe : Roman
Le main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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); } }
Erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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
Partager