Integer Cannot Be Cast To Java.util.hashmap
Im using listview on android, below code is giving error after clicking on a list item for another new activity @Override public void onItemClick(AdapterView p
Solution 1:
this is previous code on my custom adapter:
@OverridepublicObjectgetItem(int position) {
// TODO Auto-generated method stubreturn (position);
}
and this is solved code in my custom adapter:
@Overridepublic Object getItem(int position) {
// TODO Auto-generated method stubreturndata.get(position);
}
in which datais defined as ArrayList<HashMap<String, String>> data;
Solution 2:
This line
HashMap<String, String> extractor = (HashMap<String, String>) parent.getItemAtPosition(i);
causes your crash. parent is an AdapterView and returns an Integer if you call getItemAtPosition(i).
You can fix this by replacing parent with your ListAdapter (which you needed to fill your ListView). Your code should look like this afterwards:
HashMap<String, String> extractor = youListAdapter.get(i);
Solution 3:
Looks like your parent AdapterView is designed for holding int values, they will be boxed automatically to Integer. That is why by calling parent.getItemAtPosition(i) you get Integer. Obviously, Integer cannot be casted to HashMap
Post a Comment for "Integer Cannot Be Cast To Java.util.hashmap"