Je souhaite que le code suivant fonctionne dans l'environnement Java ME/J2ME. S'il vous plaît aider:Tri d'une table de hachage basée sur sa valeur d'entrée (pas la clé)
Hashtable <Activity, Float>scores = new Hashtable<Activity, Float>();
scores.put(act1, 0.3);
scores.put(act2, 0.5);
scores.put(act3, 0.4);
scores.put(act5, 0.3);
Vector v = new Vector(scores.entrySet());
Collections.sort(v); //error is related to this line
Iterator it = v.iterator();
int cnt = 0;
Activity key;
Float value;
while(it.hasNext()){
cnt++;
Map.Entry e=(Map.Entry)it.next();
key = (Activity)e.getKey();
value = (Float)e.getValue();
System.out.println(key+", "+value);
}
Il ne fonctionne pas, je reçois l'erreur:
Exception in thread "main" java.lang.ClassCastException: java.util.Hashtable$Entry cannot be cast to java.lang.Comparable This points to the line that I've indicated with a comment in the code.
s'il vous plaît aider et garder à l'esprit que j'utilise J2ME!