Jess Ian Sefulan
Jess Ian Sefulan

Reputation: 187

java.lang.String cannot be cast to android.widget.ListAdapter

I got this error trying to get all items with specific object and store it to my Listview.

Following the codes:

   SimpleDateFormat formatdate = new SimpleDateFormat("MMM. dd, yyyy");
            String selecdate = formatdate.format(date);

            if (eventDates.contains(selecdate)) {
                for (int i = 0; i < eventsList.size(); i++) {
                    HashMap<String, Object> obj = (HashMap<String, Object>) adapter.getItem(i);
                    ListAdapter list = (ListAdapter) obj.get("eventtitle");
                    myList.setAdapter(list);
                }
            }
            else {
                myList.setAdapter(null);

            }

Upvotes: 0

Views: 455

Answers (1)

Neeraj Jain
Neeraj Jain

Reputation: 7730

java.lang.String cannot be cast to android.widget.ListAdapter

This line is saying that your obj.get("eventtitle"); is returning String as a value not a ListAdapter

As docs says

public abstract Object getItem (int position)

Get the data item associated with the specified position in the data set.

So might be your dataSet is of String rather than ListAdapter

Upvotes: 1

Related Questions