Bonjour,

j'ai un peu honte de poser la question, mais j'arrive vraiment pas à trouver mon erreur. Je m'en remets donc à vous Ô Dieux du Java.

Voici le bout de code incriminé. J'ai un ClassCastException à la ligne notée // !!!

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
21
22
23
24
25
26
27
28
29
30
31
32
 
// ce bout ce code vient d'une interface que j'implémente
public HashMap<Integer, Set<EPSNode>> listEPS = new HashMap<Integer, Set<EPSNode>>();
//
 
List<EPSNode> epsList = dbConn.loadAllEPS();
Set<EPSNode> children = null;
 
// EPS nodes are already sorted
// we put it on the HashMap EPS Node -> List EPS Node children
for (EPSNode eps : epsList) {
 
	PmPlus.log.debug("Adding node "+eps.toString());
 
	// if the parent is in the map
	if(listEPS.containsKey(eps.getParentId())) {
 
		// get the list of children of this EPS and add the current EPS
		children = listEPS.get(eps.getParentId());
		children.add(eps); // !!!
 
		PmPlus.log.debug("Add a child ("+eps.id+") to existing parent ("+eps.parentId+")");
 
	} else {
		// add the parent to the map
		Set<EPSNode> child = new TreeSet<EPSNode>();
		child.add(eps);
		listEPS.put(eps.getParentId(), child);
		PmPlus.log.debug("add new parent eps ("+eps.getParentId()+")");
	}
 
}// read EPS list
Au premier tour de boucle, je suis dans le else et j'ajoute bien un couple <Integer,Set<EPSNode>> à ma HashMap.
PAf, au deuxième tour de boucle survient ce fichu ClasscastException ...

[EDIT] j'ajoute la trace au cas où. La ligne 58 est celle notée // !!!

java.lang.ClassCastException: model.PmPlusNode$EPSNode
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at model.PmPlusModelSQL.loadEPSChildren(PmPlusModelSQL.java:58)