java - Cannot cast from and ArrayList to HashMap -
i'm having problem arraylist of list of hashmaps. tried cast not allowed. here offending code:
list<list<hashmap>> myhashmaps = asyncmusichashmap.fillhashmap(path); hashmap<string, string> artisthashmap = (hashmap<string, string>) myhashmaps.get(0); hashmap<string, list<string>> albumhashmap = (hashmap<string, list<string>>) myhashmaps.get(1); hashmap<string, list<string>> songhashmap = (hashmap<string, list<string>>) myhashmaps.get(2);
with following exception message:
exception in thread "main" java.lang.classcastexception: java.util.arraylist cannot cast java.util.hashmap @ com.bkane56.mp3.mp3handlingdao.addmusictodatabase(mp3handlingdao.java:51) @ com.bkane56.mp3.mp3handler.main(mp3handler.java:21) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:497) @ com.intellij.rt.execution.application.appmain.main(appmain.java:140)
the mentioned line 51 in class mp3handlingdao is:
hashmap<string, string> artisthashmap = (hashmap<string, string>) myhashmaps.get(0);
probably simple stuck.
he has error in declaration:
list<list<hashmap>> myhashmaps = asyncmusichashmap.fillhashmap(path);
i think instruction can resolve problem because if cast myhashmaps.get(0) hashmap, list parameter maybe hashmap(string, string). try again declaration :
list<hashmap(string, string)> myhashmaps = asyncmusichashmap.fillhashmap(path);
thanks
Comments
Post a Comment