Bug 5122 - ClassCastException when using SimpleAdapter
Summary: ClassCastException when using SimpleAdapter
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-16 09:38 UTC by Roy Solberg
Modified: 2012-05-29 16:48 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_ON_ROADMAP

Description Roy Solberg 2012-05-16 09:38:37 UTC
After I upgraded to Mono for Android 4.2.1.196198126 a few days ago my app started crashing with the the error message 'java.lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.Map'.

This happens when I use the SimpleAdapter in a ListActivity.

The list adapter is instantiated using the following line in OnCreate:
ListAdapter = new SimpleAdapter(ApplicationContext, getDataList(), Resource.Layout.ListItemTrack, new string[] {LIST_ITEM_TITLE, LIST_ITEM_LOCATION, LIST_ITEM_NUM_OF_SESSIONS, LIST_ITEM_SESSIONS}, new int[] { Resource.Id.textview_title, Resource.Id.textview_location, Resource.Id.textview_num_of_sessions, Resource.Id.textview_sessions});

getDataList() looks like this:
		protected IList<IDictionary<string, object>> getDataList(){
			IList<IDictionary<string, object>> dataList = new List<IDictionary<string, object>>();
			IDictionary<string, object> dataDictionary = null;
			List<Track> tracks = ((ConferenceApplication)Application).GetTracks();
			if(tracks != null){
				foreach(Track track in tracks){
					dataDictionary = new Dictionary<string, object>();
					dataDictionary.Add(LIST_ITEM_TITLE, track.Title);
					dataDictionary.Add(LIST_ITEM_LOCATION, track.Room);
					dataDictionary.Add(LIST_ITEM_NUM_OF_SESSIONS, track.Sessions.Count);
					dataDictionary.Add(LIST_ITEM_SESSIONS, sessions);
					dataList.Add(dataDictionary);
				}
			}
			return dataList;
		}

If I comment the line with dataList.Add(dataDictionary), the crash does not occur.

The complete stacktrace is as follows:

D/AndroidRuntime(27060): Shutting down VM
E/AndroidRuntime(27060): FATAL EXCEPTION: main
E/AndroidRuntime(27060): java.lang.ClassCastException: mono.android.runtime.JavaObject cannot be cast to java.util.Map
E/AndroidRuntime(27060): 	at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:147)
E/AndroidRuntime(27060): 	at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
E/AndroidRuntime(27060): 	at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
E/AndroidRuntime(27060): 	at android.widget.AbsListView.obtainView(AbsListView.java:2033)
E/AndroidRuntime(27060): 	at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
E/AndroidRuntime(27060): 	at android.widget.ListView.onMeasure(ListView.java:1155)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(27060): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2072)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
E/AndroidRuntime(27060): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4677)
E/AndroidRuntime(27060): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
E/AndroidRuntime(27060): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2072)
E/AndroidRuntime(27060): 	at android.view.View.measure(View.java:12603)
E/AndroidRuntime(27060): 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1044)
E/AndroidRuntime(27060): 	at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
E/AndroidRuntime(27060): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(27060): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(27060): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
E/AndroidRuntime(27060): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(27060): 	at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(27060): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(27060): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(27060): 	at dalvik.system.NativeStart.main(Native Method)
Comment 1 Roy Solberg 2012-05-16 10:01:28 UTC
Using JavaDictionary instead of Dictionary seems to be a workaround for this.
Comment 3 Jonathan Pryor 2012-05-29 16:48:05 UTC
*** Bug 5281 has been marked as a duplicate of this bug. ***