ClassCastException: java.util.HashMap with android SimpleExpandableListAdapter Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of ClassCastException: java.util.HashMap with android SimpleExpandableListAdapter without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to create a simple RSS feed reader application for my mobile computing class. I’ve created a class to manage and hold RSS data.

    SimpleExpandableListAdapter rssItemList = new SimpleExpandableListAdapter(
            this,                       // context (this class)
            createTitleList(),          // Creating group List
            R.layout.parent_row,        // Group item layout XML
            new String[]{"titles"},     // the key of group item
            new int[]{},  // ID of each group item.-Data under the key goes into this TextView
            createChildList(),          // childData describes second-level entries
            R.layout.child_row,         // Layout for sub-level entries(second level)
            new String[]{"desc"},       // Keys in childData maps to display
            new int[]{}    // Data under the keys above go into these TextViews

My problem is displaying it, I’m trying to use a ExpandableListView and I keep getting an error when I try to expand an item in the list.

E/AndroidRuntime( 2542): FATAL EXCEPTION: main
E/AndroidRuntime( 2542): java.lang.ClassCastException: java.util.HashMap
E/AndroidRuntime( 2542):        at android.widget.SimpleExpandableListAdapter.getChildrenCount(
E/AndroidRuntime( 2542):        at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(
E/AndroidRuntime( 2542):        at android.widget.ExpandableListConnector.expandGroup(
E/AndroidRuntime( 2542):        at android.widget.ExpandableListView.handleItemClick(
E/AndroidRuntime( 2542):        at android.widget.ExpandableListView.performItemClick(
E/AndroidRuntime( 2542):        at android.widget.AbsListView$
E/AndroidRuntime( 2542):        at android.os.Handler.handleCallback(
E/AndroidRuntime( 2542):        at android.os.Handler.dispatchMessage(
E/AndroidRuntime( 2542):        at android.os.Looper.loop(
E/AndroidRuntime( 2542):        at
E/AndroidRuntime( 2542):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2542):        at java.lang.reflect.Method.invoke(
E/AndroidRuntime( 2542):        at$
E/AndroidRuntime( 2542):        at
E/AndroidRuntime( 2542):        at dalvik.system.NativeStart.main(Native Method)

I don’t understand why I’m getting this error, since my code for making group and child List maps are nearly the same.

@SuppressWarnings({ "unchecked", "rawtypes" })
private List createTitleList(){
    ArrayList itemTitles = new ArrayList();
    ArrayList<ItemData> entriesList = (ArrayList<ItemData>) feed.getMessages();

    for(int i = 0; i < entriesList.size(); i++){
        HashMap m = new HashMap();

        m.put("titles", entriesList.get(i).getTitle());


    return itemTitles;

@SuppressWarnings({ "unchecked", "rawtypes" })
private List createChildList(){
    ArrayList itemDesc = new ArrayList(); // item description list
    ArrayList<ItemData> entriesList = (ArrayList<ItemData>) feed.getMessages();

    for(int i = 0; i < entriesList.size(); i++){
        HashMap<String, String> m = new HashMap<String, String>();

        m.put("desc", entriesList.get(i).getDescription());


    return (List)itemDesc;

To be clear, it will display the group list, but won’t expand to show the child list.

For the benefit of future googlers, I’ve been using the following tutorials:

Expandable ListView In Android

Expandable lists


Looking at the code for SimpleExpandableListAdapter (which I have never used, so I could be wrong here), the groups field is declared as

List<? extends Map<String, ?>> 

while the children should be

List<? extends List<? extends Map<String, ?>>>

Which is to say, the children should be a list of lists of maps, not a list of maps as you seem to be providing.

I’d suggest getting rid of the lines where you suppress warnings about generic types, and actually fix the warnings rather than just hiding them. They do prevent this kind of failure, and there are very few situations where they are actually unavoidable.

We are here to answer your question about ClassCastException: java.util.HashMap with android SimpleExpandableListAdapter - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji