0

我创建了一个 Xamarin.forms 项目并创建了 DataTemplateSelector,它在 iOS 中运行良好,但在 Andoird 中,当我滚动速度更快时,应用程序不会崩溃,但是当我滚动速度较慢时,应用程序崩溃并出现 TargetInvocationException。我什至无法跟踪错误及其想要出现的错误选择,有时它不会因相同的数据而崩溃,要么滚动得更快或更慢,有时当我们尝试滚动时它会立即因相同的数据而崩溃一点点。

我已经记录了错误,以下是日志中的错误:

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 ---

下面是 xaml.cs 文件的代码

http://pastebin.com/UvyxMwtP

下面是xaml文件的代码

http://pastebin.com/VVfKAjnn

下面是 DataTemplateSelector 的代码

http://pastebin.com/nn2dGZAW

下面是模板的代码:

http://pastebin.com/0mJD1gJ1 http://pastebin.com/uJiLnBKK http://pastebin.com/gcj2TuJ1 http://pastebin.com/c8TByW1z http://pastebin.com/ww51B4Su

4

0 回答 0