我得到一個錯誤java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.HashSet
在線:(HashSet<String>) pos[targetPos3]).contains(word)
。類拋出異常HashSet
public void search(String word, Object[] root){
int targetPos1;
int targetPos2;
Object[] pos = root;
targetPos1 = word.charAt(0) -'a';
targetPos2 = word.charAt(1) -'a';
int targetPos3 = word.charAt(2) - 'a';
if(root[targetPos1]==null){
System.out.println("1st letter NOT FOUND");
}
else{
pos = (Object[]) root[targetPos1];
if(pos[targetPos2]==null){
System.out.println("2nd letter NOT FOUND");
}
else{
if(((HashSet<String>) pos[targetPos3]).contains(word)){
System.out.println("Word FOUND: " + word);
System.out.println(pos[targetPos3]);//output children
}
else{
System.out.println("NOT FOUND");
}
}
}//end of else
}
你在哪裏叫這個方法?什麼是根? – BobTheBuilder 2013-04-11 09:27:06