Bug 41118 - Scrolling ListView on Android results in Java.Lang.ArrayIndexOutOfBoundsExceptionlength=20; index=20
Summary: Scrolling ListView on Android results in Java.Lang.ArrayIndexOutOfBoundsExcep...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.2.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-16 23:03 UTC by John Hardman
Modified: 2018-02-05 10:53 UTC (History)
8 users (show)

Tags: Android ListView Scrolling Exception ArrayIndexOutOfBounds
Is this bug a regression?: ---
Last known good build:


Attachments
ProjectDemo (215.08 KB, application/x-7z-compressed)
2016-10-25 12:42 UTC, José Rossini
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 ANSWERED

Description John Hardman 2016-05-16 23:03:31 UTC
As per the thread at the following URL, I and others are getting "Java.Lang.ArrayIndexOutOfBoundsExceptionlength=20; index=20" when scrolling a ListView on Android:
https://forums.xamarin.com/discussion/65586/whats-up-with-this-new-system-runtime-exceptionservices-exceptiondispatchinfo-throw

All I do is scroll a ListView to get to the bottom of the list, and it throws the exception with the following stack trace, every time:

System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Android.Runtime.JNIEnv.CallNonvirtualBooleanMethod(IntPtr jobject, IntPtr jclass, IntPtr jmethod, JValue* parms)
Android.Views.View.DispatchTouchEvent(MotionEvent e)
Xamarin.Forms.Platform.Android.PlatformRenderer.DispatchTouchEvent(MotionEvent e)
Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_(IntPtr jnienv, IntPtr native__this, IntPtr native_e)
at (wrapper dynamic-method) System.Object:d3960dc6-7eb6-4b3a-a07f-5837bfa3e960 (intptr,intptr,intptr)
--- End of managed exception stack trace ---
java.lang.ArrayIndexOutOfBoundsException: length=20; index=20
at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6989)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5331)
at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3404)
at android.widget.AbsListView.onTouchMove(AbsListView.java:3748)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3592)
at android.view.View.dispatchTouchEvent(View.java:8048)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2243)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1967)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.n_dispatchTouchEvent(Native Method)
at md5b60ffeb829f638581ab2bb9b1a7f4f3f.PlatformRenderer.dispatchTouchEvent(PlatformRenderer.java:54)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2249)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1981)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2111)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1538)
at android.app.Activity.dispatchTouchEvent(Activity.java:2490)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2059)
at android.view.View.dispatchPointerEvent(View.java:8270)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4105)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3964)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3506)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3556)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3525)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3632)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3533)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3689)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3506)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3556)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3525)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3533)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3506)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5759)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5739)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5668)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5869)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:203)
android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:180)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5842)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5888)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:815)
at android.view.Choreographer.doCallbacks(Choreographer.java:628)
at android.view.Choreographer.doFrame(Choreographer.java:596)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:801)
at android.os.Handler.handleCallback(Handler.java:755)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5266)
java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:826)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:642)
dalvik.system.NativeStart.main(Native Method)
Comment 1 John Hardman 2016-05-16 23:05:56 UTC
I should have mentioned, I am using XF 2.2.0.31
Comment 2 Andy 2016-07-12 19:32:06 UTC
Happening to me too when I remove and item from the list view.
Comment 3 Rui Marinho 2016-08-04 15:09:35 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it.

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d Warm regards, Xamarin Forms Team
Comment 4 José Rossini 2016-10-25 12:42:22 UTC
Created attachment 18212 [details]
ProjectDemo

I manage to reproduce the same error, switching the listview itemtemplate, it's  the amount of time that happen, causing the Java exception.
Comment 5 Andy 2016-10-25 12:58:38 UTC
You shouldn't be switching the listview item template. Use a DataTemplateSelector if you want to have different templates. For me, this was caused by me creating a new itemtemplate each time the DataTemplateSelector was ready.


listView = new ListView()
{
    ....
    ItemTemplate = new CommentDataTemplateSelector(),
    ....
}


    class SpecialDataTemplateSelector : DataTemplateSelector
    {
		//The DataTemplate should only be created one time, there is a limit of 20 types,
		//and if you add a new DataTemplate each time, you will hit that limit
        private readonly DataTemplate special1Template = new DataTemplate(typeof(Special1Cell));
        private readonly DataTemplate special2Template = new DataTemplate(typeof(Special2Cell));

        protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
        {
            SpecialClass sc = item as SpecialClass;

            if (item.HasCharacteristic1() == true)
            {
                return special1Template;
            }
            else
            {
                return special2Template ;
            }
        }
    }
Comment 6 José Rossini 2016-10-26 10:24:13 UTC
Thanks Andy!
Comment 7 AndyB 2016-11-11 22:46:26 UTC
Thanks Andy.  Switching the ItemTemplate multiple times was causing the issue. <3
Comment 8 Samantha Houts [MSFT] 2016-12-01 17:58:35 UTC
@John Hardman:

I presume that the later comments on this bug are not related to your original report. Do you have a reproduction project your could provide to help us diagnose the issue?

Thanks!
Comment 9 John Hardman 2016-12-01 18:22:04 UTC
@Samantha Houts - I'm not seeing this problem any more. I am using a DataTemplateSelector to switch between multiple templates. If you want to close this bug, I'm happy to raise a new one if I see the problem again.
Comment 10 Samantha Houts [MSFT] 2016-12-01 20:18:30 UTC
Outstanding! Thank you very much!
Comment 11 Andy 2016-12-01 20:25:14 UTC
Great job.
Comment 12 Devi Prasad 2018-02-05 10:53:23 UTC
Wow I exception gone away thank you Andy