0

I am using Xamarin.Forms v2.4.0.38779 and I am facing Null Pointer exception which crashes the application. I had same issue with 2.4.0.18342

System.NullReferenceException: Object reference not set to an instance of an object

I guess, Issue occcured while I have ListView with few rows and I am adding new rows, deleting existing rows and also updating values of row based on values, I get from background thread.

As data comes too frequently, around 100 updates in matter of seconds, It crashes.

FYI, I have ObservationCollection binded to ItemSource of ListView. So I dont manage addition, removal and update myself.

Here is 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)

Does anyone has idea on how to resolve this?

FYI, This is not about how to resolve NullPointerException, as Xamarin.Forms code is not own by me. I am using that as third party module.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Hardik Patel
  • 123
  • 10
  • I'd vote to reopen, but I expect your question would get re-closed for a different reason because you haven't explained how you are reproducing this error, or shown us the code that triggers it. – Blorgbeard Nov 01 '17 at 16:28
  • Hey @owen-pauling, This is not about generic NullPointerException that occurred in my code. This is about Third party module Xamarin.Forms and I am facing issue due to its code. Could you please remove duplicate tag from the issue? – Hardik Patel Nov 01 '17 at 16:30
  • Hey @Blorgbeard, I have just updated the case with what I think, causing issue. I dont have exact understanding on when it would crash. As It happen randomly but frequently. – Hardik Patel Nov 01 '17 at 16:34
  • OK, I'm convinced. I've reopened your question. I don't have experience with Xamarin, but hopefully someone else can help you now. – Blorgbeard Nov 01 '17 at 16:39
  • Although actually, the background thread thing sounds suspicious. You shouldn't be interacting with UI elements from any thread except the main UI thread. You may need to dispatch updates to the main thread as they come in. – Blorgbeard Nov 01 '17 at 16:41
  • @Blorgbeard Yes, UI Update happens only once on UI Thread at that time of list binding but then updates to list are coming from various thread. But I am making sure only one thread is accessing list at a time – Hardik Patel Nov 01 '17 at 17:18

2 Answers2

0

Changing the CachingStrategy on the listview also seems to be a workaround. Based on https://bugzilla.xamarin.com/show_bug.cgi?id=59813.

For me it was fixed changing CachingStrategy to RecycleElement, but from the link above it has also been reported that changing to RetainElement can be a fix.

Andreas
  • 11
  • 2