Bug 39451 - Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle
Summary: Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAd...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.1.0
Hardware: Other Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-03-08 15:24 UTC by Kasper
Modified: 2018-04-06 18:45 UTC (History)
18 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 ANSWERED

Description Kasper 2016-03-08 15:24:10 UTC
With Xamarin.Forms 2.1.0.6524 and Xamarin.Android 6.0.99.544 I frequenbtly get an error like this:

03-08 16:05:20.093 25388 25388 E AndroidRuntime: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	... 1 more
03-08 16:05:20.093 25388 25388 E AndroidRuntime: Caused by: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0x7fc5d26c94 (key_handle 0x490851a). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.ListViewAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
03-08 16:05:20.093 25388 25388 E AndroidRuntime: Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   --- End of managed exception stack trace ---
03-08 16:05:20.093 25388 25388 E AndroidRuntime: java.lang.Error: Java callstack:
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ListViewAdapter.n_getCount(Native Method)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ListViewAdapter.getCount(ListViewAdapter.java:68)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.HeaderViewListAdapter.getItemViewType(HeaderViewListAdapter.java:232)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.AbsListView$RecycleBin.getScrapView(AbsListView.java:6593)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.AbsListView.obtainView(AbsListView.java:2345)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.ListView.makeAndAddView(ListView.java:1876)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.ListView.fillDown(ListView.java:702)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.ListView.fillGap(ListView.java:666)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5053)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4601)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.view.Choreographer.doCallbacks(Choreographer.java:670)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.view.Choreographer.doFrame(Choreographer.java:603)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:739)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:95)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:148)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   --- End of inner exception stack trace ---
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) <0x7f92989bb0 + 0x001ec> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) <0x7f9299c7a0 + 0x002db> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   --- End of inner exception stack trace ---
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) <0x7f9299c7a0 + 0x00594> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Lang.Object.GetObject (IntPtr handle, JniHandleOwnership transfer, System.Type type) <0x7f9299be90 + 0x0033f> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Lang.Object._GetObject[T] (IntPtr handle, JniHandleOwnership transfer) <0x7f9299bd08 + 0x0004b> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Lang.Object.GetObject[T] (IntPtr handle, JniHandleOwnership transfer) <0x7f9299bac0 + 0x0002b> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Java.Lang.Object.GetObject[T] (IntPtr jnienv, IntPtr handle, JniHandleOwnership transfer) <0x7f924e6510 + 0x00037> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at Android.Widget.BaseAdapter.n_GetCount (IntPtr jnienv, IntPtr native__this) <0x7f851285b8 + 0x0002b> in <filename unknown>:0 
03-08 16:05:20.093 25388 25388 E AndroidRuntime:   at (wrapper dynamic-method) System.Object:8d068a3c-da14-4035-b06f-19d14718c90d (intptr,intptr)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ListViewAdapter.n_getCount(Native Method)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.ListViewAdapter.getCount(ListViewAdapter.java:68)
03-08 16:05:20.093 25388 25388 E AndroidRuntime: 	at android.widget.HeaderViewListAdapter.getItemViewType(HeaderViewLi

My setup is currently running:

=== Xamarin Studio ===

Version 6.0 (build 4520)
Installation UUID: 32815239-f9d8-4d2d-a24b-0f4c02244210
Runtime:
	Mono 4.3.2 (mono-4.3.2-branch/ba2e5e4) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 403020467

=== Xamarin.Profiler ===

Version: 0.0.0.0
Location: /Users/kasper/Downloads/profiler-mac-0.9-0/XamarinProfiler.Mac.app/Contents/MacOS/XamarinProfiler.Mac

=== Apple Developer Tools ===

Xcode 7.2.1 (9548.1)
Build 7C1002

=== Xamarin.iOS ===

Version: 9.8.0.43 (Business Edition)
Hash: 4390115
Branch: master
Build date: 2016-03-03 18:17:12-0500

=== Xamarin.Android ===

Version: 6.0.99.544 (Business Edition)
Android SDK: /Users/kasper/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 25.0.7 rc8
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.8.0.42 (Starter Edition)

=== Build Information ===

Release ID: 600004520
Git revision: a354b2cb9df4b96f50b0ccb960dbdd5a9155510c
Build date: 2016-02-18 14:52:07-05
Xamarin addins: 8e54979f23feee160d245a3c33e43e77779b1eb4
Build lane: monodevelop-lion-master

=== Operating System ===

Mac OS X 10.11.3
Darwin Kaspers-MacBook-Pro.local 15.3.0 Darwin Kernel Version 15.3.0
    Thu Dec 10 18:40:58 PST 2015
    root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
Comment 1 Kasper 2016-03-08 15:44:21 UTC
A similar problem can happen with ConditionalFocusLayout:

03-08 16:39:55.813 31859 31859 E AndroidRuntime: Caused by: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ConditionalFocusLayout from native handle 0x7fc5d26ca8 (key_handle 0xe5d4fb0). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.ConditionalFocusLayout::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
03-08 16:39:55.813 31859 31859 E AndroidRuntime: Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
Comment 2 Paul DiPietro [MSFT] 2016-03-10 20:21:40 UTC
If you could possibly provide a reproduction project showing the error at least somewhat reliably, it would be much appreciated in investigating the issue.
Comment 3 Kasper 2016-03-11 12:17:14 UTC
Currently I don't have the time to try and create a small reproduction project. I have reverted to the BETA channel and haven't seen the issue since.
Comment 5 Jason Smith [MSFT] 2016-03-13 11:43:59 UTC
@Kasper, what exactly are you doing when this happens? Usually this is the result of an improper cleanup of a renderer.
Comment 6 Kasper 2016-03-13 12:02:46 UTC
@Jason Smith
I'm not using any custom renderers on the pages where I have seen this.

I simply use the app, scroll some lists, navigate between pages, then suddenly it crashes with:

E AndroidRuntime: Caused by: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.<SOMETHING> from native handle 0x7fc5d26ca8 (key_handle 0xe5d4fb0). ---> System.MissingMethodException: No constructor found ...

Especially I'm not inheriting from either of:
Xamarin.Forms.Platform.Android.ListViewAdapter
Xamarin.Forms.Platform.Android.ConditionalFocusLayout

(the two classes with "missing" ctors, from above)

As mentioned I'm using the latest stable XF 2.1.0.6526, but the issue only occur with ALPHA channel in Xamarin Studio.

I know I raised it against XF, since it is always the ctor of some XF Android renderer that is "missing", but I believe it has to do with the latest X.Android 6.0.99.544.

Anyway, I never see it when using the BETA channel, ie. X.Android 6.0.2.1.

In particular I suspect the new Java interop stuff:
https://developer.xamarin.com/releases/android/xamarin.android_6/xamarin.android_6.1/#Java_Interop

but it's just a hunch.

I'm sorry I do not have a simple reproduction :-/

Best regards, Kasper
Comment 7 Jason Smith [MSFT] 2016-03-15 20:27:37 UTC
You can probably work around this in the mean time by making a ListView renderer for this listview you have issues with and overriding dispose without calling base.
Comment 8 Samantha Houts [MSFT] 2016-03-18 17:45:09 UTC
@Kasper,

Do you happen to have any views nested in the header/footer of the ListView?

Thanks!
Comment 9 Kasper 2016-03-19 10:59:43 UTC
@Samantha Yes, I do have a header with a fairly complex gridview
Comment 10 Samantha Houts [MSFT] 2016-03-21 21:31:05 UTC
@Kasper,

That's good news! I believe that you are encountering the same issue as described in https://bugzilla.xamarin.com/show_bug.cgi?id=32462, which should be fixed in 2.2.0-pre1. I will mark this bug as a duplicate for now, if you do not mind.

Thank you!

*** This bug has been marked as a duplicate of bug 32462 ***
Comment 11 T. Krieger 2017-08-01 07:19:08 UTC
I Still have this issue with the newest version of Xamarin

Known difference is that it is a Listview inside a Listview.

I will attach a sample project to reproduce the bug.
Comment 12 T. Krieger 2017-08-01 07:29:28 UTC
Unable to make a attachment download url so here it is:
https://mega.nz/#!E1tggYLR!Rmpqv_bBnOiV-45uiEZuz3TZAxzttIcHK6P8e3UHPoY

Kind Regards,
Comment 13 vinnie1991 2017-08-03 09:53:44 UTC
I've the same as T. Krieger.
A Listview in a ListView/TableView makes the App crash.

The first time the View is shown there isn't a problem. But when the view goes out of the view, and then back the app will crash.
Error is:

Unable to activate instance of type Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0xffccb7ac (key_handle 0xb2894b1). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.ListViewAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
Comment 14 ctacke 2017-08-14 23:42:08 UTC
I also can confirm that a Xamarin Forms ListView inside of a ListView on Android fails with the latest Xamarin binaries  Exact same code under UWP works just fine.  I have a repro app, but it requires a specific BTLE device (Estimote) to cause the issue since that's what I'm working on, so this is not fully resolved.
Comment 15 ctacke 2017-08-14 23:47:20 UTC
The repro can be found here:

https://github.com/ctacke/universal-beacon

Use commit 3b836b5bfa5aee3a458ea74c8da57592ea659af4.

The EddystoneTLMViewCell is what kills it.  Commenting out the internal ListView eliminates the issue.
Comment 16 ctacke 2017-08-18 03:26:30 UTC
I've merged the fork back into the trunk.  The commit number is the same, but it's now here: https://github.com/andijakl/universal-beacon
Comment 17 Tom Krueger 2017-09-04 13:09:48 UTC
I also get the same problem.  When I have a ListView inside of a ListView.  My  Android app throws and unhandled exception.

Additional Info:
My page is the first page of the app.  

Interestingly, it only happens when using NavigationPage.  If I set my MainPage in app.xaml.cs directly to my page, then it works fine.  However, if I set MainPage to a NavigationPage that directs to my page then the unhandled exception occurs.

Unhandled Exception Message:
System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle 0x42b0003d (key_handle 0xa90094f8). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.ListViewAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.

Thanks for the help!
Comment 18 abdullah 2017-10-09 10:16:53 UTC
i'm getting this when writing custom renderer for ViewCellRenderer in GetCellCore
this appear when trying to click many times of different cells 

i fix this 

 if (cell== null)
{
cell = base.GetCellCore(item, convertView, parent, context);
}
Comment 19 cunnpole 2017-11-07 15:35:37 UTC
I'm experiencing this too. Is anyone at MSFT still monitoring this?
Comment 20 Santyy 2017-11-24 10:26:41 UTC
Am facing this issue. ListView inside ListView makes the app crash while scrolling.
Comment 21 Daniel Tabares 2017-11-27 17:41:39 UTC
The same issue, app crash while scrolling, I am using a DataTemplateSelector
Comment 22 Alper Ebicoglu 2017-12-02 18:25:28 UTC
Same thing happened to me as well. I have a ListView, and inside the ListView template there's another ListView. When I navigate to another view and come back, it throws this exception.  Actually I do not know any other component to populate a repeating template inside a ListView. 

Imagine I have Contacts view populated with ListView. Each list view item is a contact. Each contact has N phone numbers. How can I repeat the phone numbers in the list view template?
Comment 23 Alper Ebicoglu 2017-12-02 18:26:39 UTC
By the way my Xamarin.Forms version is 2.5.0.91635.
Comment 24 ALexey Starkov 2018-01-08 16:11:41 UTC
I have same problem for ListView in ListView.
Comment 25 Paul DiPietro [MSFT] 2018-01-08 16:14:24 UTC
Nested ListViews are not supported. If there is a scenario where this crash occurs without nested ListViews, please open a new issue on GitHub.
Comment 26 Shafiq 2018-01-09 17:57:24 UTC
If nested listviews are not supported, then what are our options for doing nested lists of indeterminate size? I've been working on this same problem for weeks and this seems to be the only solution that I've made work properly.
Comment 27 zafar 2018-01-17 17:50:28 UTC
I had the same exception "Unable to activate instance of type Xamarin.Forms.Platform.Android.ListViewAdapter from native handle". I was able to resolve when I modified the access specifier of the custom Renderer class from internal to public
Comment 28 zafar 2018-01-17 18:23:57 UTC
@Shafiq
Use ListView.Header and List.Footer properties if you need any content above or below the listview instead of nesting it under a parent control.
Comment 29 Artem T 2018-04-06 18:45:55 UTC
If Nested ListViews are not supported, wouldn't it be better then to provide a more meaningful exception message? For example, "Nested ListViews are not supported. Please remove ListView from a ListView"