Xamarin.forms: [Android] NullReferenceException at IOnTimeSetListener.OnTimeSet

Created on 4 Jun 2018  Â·  6Comments  Â·  Source: xamarin/Xamarin.Forms

Description

I've seen some crashes caused by the XF Android TimePickerRenderer.
Unfortunately it seems not possible to reproduce the crash.

System.NullReferenceException: Object reference not set to an instance of an object
at IOnTimeSetListener.OnTimeSet (Android.Widget.TimePicker view, System.Int32 hourOfDay, System.Int32 minute)
at TimePickerDialog+IOnTimeSetListenerInvoker.n_OnTimeSet_Landroid_widget_TimePicker_II (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_view, System.Int32 hourOfDay, System.Int32 minute)

Crash on Galaxy S7 Edge.txt
Crash on Galaxy S8 Plus.txt

Steps to Reproduce

  1. Run Xamarin Forms App on Android
  2. Pick a 24h based Time using XF TimePicker
  3. It will crash, at least sometimes

Expected Behavior

The user is able to pick a time without crashing the app

Actual Behavior

The user picks a time and the app will crash, at least sometimes

Basic Information

  • Version with issue: 3.0.0.482510
  • Last known good version: unknown
  • IDE: Visual Studio 15.7.2
  • Android Target Framework: 8.1 (API Level 27)
  • Android Support Library Version: 27.0.2
  • Nuget Package: Xamarin.Forms: 3.0.0.482510
  • Affected Devices:
    Samsung Galaxy S7 Edge (SM-G935F)
    Samsung Galaxy S8 Plus (SM-G955F)

Screenshots

app center crash group

2 Android bug

All 6 comments

@crazynolde sounds like this bug https://github.com/xamarin/Xamarin.Forms/issues/2191

The DatePicker and TimePicker do not have double tap protection. To reproduce, double-tap on the time picker and notice 2 dialog boxes appear.

Tapping OK on the second dialog box will result in a NRE

There is a workaround, if needed, in the comments of the issue that I have implemented for now.

@AntRemo Seems to be simmilar… thank you.

Also on Dispose these renderers need to unhook events

Fixed by #3899.

@hartez I know this is an old issue, but I just found another way to cause this error. It results from TimePickerRenderer not implementing Dispose like the DatePickerRenderer does. I can replicate the issue by opening the time picker, then having another task navigate back to another back page (for example with a delayed task, in my case from a notification tap). At that point the TimePickerDialog is open but the originating page has been disposed. Tapping Ok or Cancel will cause the error indicated in this issue.

TimePickerRenderer: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs

DatePickerRenderer Dispose:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/Renderers/DatePickerRenderer.cs#L36

@AntRemo Please open a new issue - otherwise this is likely to get lost in the shuffle.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joseluisct picture joseluisct  Â·  3Comments

Stensan picture Stensan  Â·  3Comments

xabre picture xabre  Â·  3Comments

simontocknell picture simontocknell  Â·  3Comments

MartinWegner picture MartinWegner  Â·  3Comments