How to solve errors occuring while scrolling in Android not in iOS in DataTemplateSelector?

I've created a ListView and I need to show the posts with multiple tamplates so, I've created the DataTemplateSelector to choose a template. When I run the application in iOS it runs fine and no error comes while scrolling but, when I run in Android, application runs fine. Now I start scrolling faster and no error comes but when I try to scroll slower it throws TargetInvocationException and I'm not able to catch it because I don't know exactly where it comes. when I remove images from Templates then the app works fine. Sometimes Android app automatically don't crash either scrolled faster or slower.

You can see the attached files of templates, template selector and the page where the error is coming.

I've logged the error in Android device. The error is below:

    Time: 12/14/2016 1:37:48 PM
    Error: Unhandled Exception
    System.Exception: CurrentDomainOnUnhandledException ---> Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException ---> Java.Lang.Reflect.InvocationTargetException: Exception of type 'Java.Lang.Reflect.InvocationTargetException' was thrown. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
      at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00011] in <368820a9888f43ddb85d18e87189adbf>:0 
      at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <368820a9888f43ddb85d18e87189adbf>:0 
      at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x0000c] in <368820a9888f43ddb85d18e87189adbf>:0 
      at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
      at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <368820a9888f43ddb85d18e87189adbf>:0 
       --- End of inner exception stack trace ---
      at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00056] in <368820a9888f43ddb85d18e87189adbf>:0 
      at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <368820a9888f43ddb85d18e87189adbf>:0 
      at Xamarin.Forms.BindingExpression+BindingExpressionPart.TryGetValue (System.Object source, System.Object& value) [0x00026] in <7b0368eb3d0f405da776a09e3171532a>:0 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <368820a9888f43ddb85d18e87189adbf>:0 
      at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualBooleanMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x000a8] in <a043032cf94a485190047a14918b9f60>:0 
      at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00068] in <a043032cf94a485190047a14918b9f60>:0 
      at Android.Views.View.DispatchTouchEvent (Android.Views.MotionEvent e) [0x00036] in <206240d88f7f44d795aacbc1d5348a1f>:0 
      at Xamarin.Forms.Platform.Android.PlatformRenderer.DispatchTouchEvent (Android.Views.MotionEvent e) [0x00035] in <d572ae0ccf89437fad1de1370c623a06>:0 
      at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00011] in <206240d88f7f44d795aacbc1d5348a1f>:0 
      at (wrapper dynamic-method) System.Object:035bfbdb-dd96-451c-b894-4f2fd770769d (intptr,intptr,intptr)
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
Sign In or Register to comment.