Bug 5198 - Crash when using SimpleAdapter after update to latest Mono for Android
Summary: Crash when using SimpleAdapter after update to latest Mono for Android
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-21 05:02 UTC by Maxim
Modified: 2012-05-30 02:20 UTC (History)
2 users (show)

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


Attachments
Simple example (424.58 KB, application/x-zip)
2012-05-22 10:46 UTC, Maxim
Details
Variable types (407.34 KB, image/png)
2012-05-22 10:47 UTC, Maxim
Details


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 Maxim 2012-05-21 05:02:51 UTC
After update to latest product stack, fatal error when using SimpleAdapter appear in emulator.

Code:
            SetContentView(Resource.Layout.ChooseProfileForm);
			
			profilesRawList = new List<UserProfile>();
            try {
                profilesRawList = EMIASSingletone.db().QueryUserProfiles().ToList();
            }
            catch (Exception e) {
                RunOnUiThread(delegate {
                    ProgressDialog.Show(this, "Error", "Problem with DB: " + e.Message); 
                });
            }
            
            if (profilesRawList.Count > 0) {
                profilesRawList = profilesRawList.OrderBy(a => a.fullName).ToList();
                profilesList = new List<IDictionary<string, object>>();
                foreach (UserProfile profile in profilesRawList) {
                    Dictionary<string, object> map = new Dictionary<string, object>();
                    map.Add("cfio", profile.fullName);
                    map.Add("cbday", profile.dateOfBirth.ToShortDateString());
                    map.Add("NID", profile.Id); 
                    profilesList.Add(map);
                }
            
                listViewAdapter = new SimpleAdapter(this, profilesList, Android.Resource.Layout.SimpleListItem2, columns, listItemIds );

				RunOnUiThread(delegate {
                    profilesListView = (ListView) FindViewById(Resource.Id.list);
                    profilesListView.Adapter = listViewAdapter;
                    RegisterForContextMenu(profilesListView);
                    profilesListView.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) {
						ProceedItemClick(this, e);
					};
                });
            }

Stacktrace:
D/AndroidRuntime(  371): Shutting down VM
E/AndroidRuntime(  371): FATAL EXCEPTION: main
E/AndroidRuntime(  371): java.lang.ClassCastException: mono.android.runtime.JavaObject
E/AndroidRuntime(  371): 	at android.widget.SimpleAdapter.bindView(SimpleAdapter.java:147)
E/AndroidRuntime(  371): 	at android.widget.SimpleAdapter.createViewFromResource(SimpleAdapter.java:126)
E/AndroidRuntime(  371): 	at android.widget.SimpleAdapter.getView(SimpleAdapter.java:114)
E/AndroidRuntime(  371): 	at android.widget.AbsListView.obtainView(AbsListView.java:1430)
E/AndroidRuntime(  371): 	at android.widget.ListView.makeAndAddView(ListView.java:1745)
E/AndroidRuntime(  371): 	at android.widget.ListView.fillDown(ListView.java:670)
E/AndroidRuntime(  371): 	at android.widget.ListView.fillFromTop(ListView.java:727)
E/AndroidRuntime(  371): 	at android.widget.ListView.layoutChildren(ListView.java:1598)
E/AndroidRuntime(  371): 	at android.widget.AbsListView.onLayout(AbsListView.java:1260)
E/AndroidRuntime(  371): 	at android.view.View.layout(View.java:7175)
E/AndroidRuntime(  371): 	at android.widget.AbsoluteLayout.onLayout(AbsoluteLayout.java:120)
E/AndroidRuntime(  371): 	at android.view.View.layout(View.java:7175)
E/AndroidRuntime(  371): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(  371): 	at android.view.View.layout(View.java:7175)
E/AndroidRuntime(  371): 	at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
E/AndroidRuntime(  371): 	at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
E/AndroidRuntime(  371): 	at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
E/AndroidRuntime(  371): 	at android.view.View.layout(View.java:7175)
E/AndroidRuntime(  371): 	at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
E/AndroidRuntime(  371): 	at android.view.View.layout(View.java:7175)
E/AndroidRuntime(  371): 	at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
E/AndroidRuntime(  371): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
E/AndroidRuntime(  371): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  371): 	at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  371): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(  371): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  371): 	at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  371): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(  371): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(  371): 	at dalvik.system.NativeStart.main(Native Method)



Version info:
MonoDevelop 3.0 (3.0.1)
Installation UUID: 67e740eb-2804-420e-8ab5-4e5d7696ac6b
Runtime:
	Mono 2.10.9 (tarball Mon May  7 20:25:51 EDT 2012)
	GTK 2.24.10
	GTK# (2.12.0.0)
	Package version: 210090011
Mono for Android: 4.2.1.196198126
Android SDK: /Users/fvs/Library/Developer/Xamarin/android-sdk-mac_x86
Supported Android versions:
	Version: 1.6	ApiLevel: 4
	Version: 2.1	ApiLevel: 7
	Version: 2.2	ApiLevel: 8
	Version: 2.3	ApiLevel: 10
	Version: 3.1	ApiLevel: 12
	Version: 4.0	ApiLevel: 14
	Version: 4.0.3	ApiLevel: 15
Java SDK: /usr/bin

Apple Developer Tools:
	 Xcode 4.3.2 (1177)
	 Build 4E2002
Monotouch: 5.2.11
Build information:
	Release ID: 30001000
	Git revision: 6642975fcf75fabbaf71a2ce79cdd65cd7db812a-dirty
	Build date: 2012-05-14 11:09:56+0000
	Xamarin addins: a1563f182f5d7a68e0ba06beda0a39f9fe073016
Operating System:
	Mac OS X 10.7.4
	Darwin fvss-mac-mini.lan 11.4.0 Darwin Kernel Version 11.4.0
	    Mon Apr  9 19:32:15 PDT 2012
	    root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64
Comment 1 Maxim 2012-05-21 05:15:51 UTC
Yep, guys, I found a related issue https://bugzilla.xamarin.com/show_bug.cgi?id=5122 and check solution from http://lists.ximian.com/pipermail/monodroid/2012-May/010304.html to one of my ListView.

Seems like it fix the issue.

Questions:
1. Is it possible to implement type checking at compilation stage? Cause now data could be Dictionaries and Lists and only runtime checking showing error.
2. Could you make an ftp or dedicated wiki page with links to previous product stack versions?
I had an critical issue in iPhone version #5167, so such archive of old releases could help me and other customers much when something going wrong.
Comment 2 Maxim 2012-05-22 09:02:13 UTC
Having a problem with SimpleExpandableListAdapter.
Could you show an example to make fix when using adapter of this type?
Comment 3 Maxim 2012-05-22 10:46:05 UTC
Created attachment 1942 [details]
Simple example

Based on http://stackoverflow.com/questions/8674628/expandablelistview-mono-for-android, which surely WORKED with previous Mono for Android versions.
Comment 4 Maxim 2012-05-22 10:47:16 UTC
Created attachment 1943 [details]
Variable types

Debugger show that variable have needed types.
Comment 5 Maxim 2012-05-22 10:50:43 UTC
I made an example based on http://stackoverflow.com/questions/8674628/expandablelistview-mono-for-android and check the parameters types. Seems like they have types, which are right according to solutions in mailing list and bug #5122.

Example and screenshot are attached.
Comment 6 Maxim 2012-05-22 11:01:14 UTC
Stack trace:
D/AndroidRuntime( 7412): Shutting down VM
E/AndroidRuntime( 7412): FATAL EXCEPTION: main
E/AndroidRuntime( 7412): java.lang.ClassCastException: mono.android.runtime.JavaObject
E/AndroidRuntime( 7412): 	at android.widget.SimpleExpandableListAdapter.bindView(SimpleExpandableListAdapter.java:249)
E/AndroidRuntime( 7412): 	at android.widget.SimpleExpandableListAdapter.getGroupView(SimpleExpandableListAdapter.java:278)
E/AndroidRuntime( 7412): 	at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:445)
E/AndroidRuntime( 7412): 	at android.widget.AbsListView.obtainView(AbsListView.java:1430)
E/AndroidRuntime( 7412): 	at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
E/AndroidRuntime( 7412): 	at android.widget.ListView.onMeasure(ListView.java:1127)
E/AndroidRuntime( 7412): 	at android.view.View.measure(View.java:8313)
E/AndroidRuntime( 7412): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
E/AndroidRuntime( 7412): 	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
E/AndroidRuntime( 7412): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
E/AndroidRuntime( 7412): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
E/AndroidRuntime( 7412): 	at android.view.View.measure(View.java:8313)
E/AndroidRuntime( 7412): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
E/AndroidRuntime( 7412): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
E/AndroidRuntime( 7412): 	at android.view.View.measure(View.java:8313)
E/AndroidRuntime( 7412): 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
E/AndroidRuntime( 7412): 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
E/AndroidRuntime( 7412): 	at android.view.View.measure(View.java:8313)
E/AndroidRuntime( 7412): 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
E/AndroidRuntime( 7412): 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
E/AndroidRuntime( 7412): 	at android.view.View.measure(View.java:8313)
E/AndroidRuntime( 7412): 	at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
E/AndroidRuntime( 7412): 	at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
E/AndroidRuntime( 7412): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7412): 	at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 7412): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 7412): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 7412): 	at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 7412): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 7412): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 7412): 	at dalvik.system.NativeStart.main(Native Method)
I/Process ( 7412): Sending signal. PID: 7412 SIG: 9

Hope it helps.
Comment 7 Jonathan Pryor 2012-05-29 16:43:36 UTC
I must say that I'm getting confused about the thread; it seems that Comment #1 should have obviated the need for Comments 2-6, as using JavaList/etc. instead of List/etc. fixes the issue (as per bug #5122).

The ClassCastException in Comment #6 is likewise dup of #5122.

I've updated the sample code at http://stackoverflow.com/questions/8674628/expandablelistview-mono-for-android so that it's valid for v4.2.1 and later.

Is there a remaining bug/question/concern?

Thanks,
 - Jon
Comment 8 Jonathan Pryor 2012-05-29 17:00:20 UTC
Answering the questions from Comment #1:

> 1. Is it possible to implement type checking at compilation stage?

Filed as: https://bugzilla.xamarin.com/show_bug.cgi?id=5401

> 2. Could you make an ftp or dedicated wiki page with links to previous product stack versions?

You can find previous product versions at: https://store.xamarin.com/account/products
Comment 9 Maxim 2012-05-30 02:20:03 UTC
My comments 2-6 are about that solution solves the issue when using SimpleAdapter, but not when using SimpleExpandableListAdapter.

You are using var-type declaration, when I using IList<SomeThing>. I'll recheck my SimpleExpandableListAdapter according to your updated example and will confirm solution.