我正在使用Xamarin.Forms v2.4.0.38779,我正面临Null Pointer异常,它会导致应用程序崩溃。我和2.4.0.18342有同样的问题
System.NullReferenceException: Object reference not set to an instance of an object
我想,当我有少量行的ListView时,问题就出现了,我正在添加新行,删除现有行,并根据值更新行的值,我从后台线程获取。
由于数据过于频繁,大约100次更新几秒钟,它崩溃了。
仅供参考,我将ObservationCollection绑定到ListView的ItemSource。所以我不管理添加,删除和更新自己。
这是stackttrace:
LabelRenderer.UpdateText ()
LabelRenderer.OnElementPropertyChanged (System.Object sender,System.ComponentModel.PropertyChangedEventArgs e)
(wrapper delegate-invoke) :invoke_void_object_PropertyChangedEventArgs object,System.ComponentModel.PropertyChangedEventArgs)
BindableObject.OnPropertyChanged (System.String propertyName)
Element.OnPropertyChanged (System.String propertyName)
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property,
Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes,
Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget)
BindingExpression.Apply (System.Boolean fromTarget)
BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 ()
NSAsyncActionDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.String principalClassName,System.String delegateClassName)
Application.Main (System.String[] args)
有没有人知道如何解决这个问题?
仅供参考,这不是关于如何解决NullPointerException,因为我不拥有Xamarin.Forms代码。我将其用作第三方模块。
答案 0 :(得分:1)
https://bugzilla.xamarin.com/show_bug.cgi?id=59813
https://github.com/xamarin/Xamarin.Forms/pull/1226
将HasUnevenRows设置为false并手动设置RowHeight为我工作。
答案 1 :(得分:0)
更改listview上的CachingStrategy似乎也是一种解决方法。基于https://bugzilla.xamarin.com/show_bug.cgi?id=59813。
对我而言,修复了将CachingStrategy更改为RecycleElement的问题,但是从上面的链接也可以看到更改为RetainElement可能是一个修复。