Crash on Android

AmriRahmaAmriRahma Member ✭✭

Hi,
Below is the crash log, does anyone know why its crashing in android.

AvailabilityViewModel+d__45.MoveNext ()
System.NullReferenceException: Object reference not set to an instance of an object

This the function CellTapped :

private async void CellTapped(object sender, CalendarCell e)
{
this.IsBusy = true;

        if (e is CalendarDayCell dayCell)
        {
            if(dayCell != null)
            {
                DateTime date = dayCell.Date;
                List<IAppointment> availability = (sender as RadCalendar)?.AppointmentsSource?.Where(a => a.StartDate.Date == date).ToList();

                if (availability == null || !availability.Any())
                {
                    if (date.Date < DateTime.Now.Date)
                    {
                        await this.DialogsService.ShowAlertAsync("Non è possibile inserire disponibilità per date passate.", "Informazione", "OK");
                    }
                    else
                    {
                        /* ANCORA NON SONO STATE INSERITE DISPONIBILITA' PER LA DATA SELEZIONATA 
                         * IMPOSTAZIONE RAPIDA: "DISPONIBILITA' DI TUTTA LA GIORNATA" */
                        DateTime startDate = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
                        DateTime endDate = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59);

                        Shift newShift = new Shift()
                        {
                            ID = 0,
                            IsAllDay = true,
                            StartDate = startDate,
                            EndDate = endDate,
                            Detail = "New",
                            Title = "New",
                            Slot = 1,
                            ToSend = false
                        };

                        // LO AGGIUNGO ALLA LISTA PER POTERLO VISUALIZZARE NEL CALENDARIO
                        this.AvailabilityList.Add(newShift);

                        // LO SALVO IN LOCALE
                        await this.TaleteService.SaveShiftLocal(newShift)
                            .ContinueWith(
                                async a =>
                                {
                                    await this.HandleShiftsPresentationAsync();
                                },
                                TaskScheduler.FromCurrentSynchronizationContext()).ConfigureAwait(false);
                    }
                }
                else
            {
                // APRO IN MODIFICA
                await PopupNavigation.Instance.PushAsync(new AvailabilityPopUpView());

                // DEVO VERIFICARE SE AVEVO ASSEGNATO PRECEDENTEMENTE LO SLOT
                if(availability.Count > 1)
                {
                    if((availability.First() as Shift).ID == 0 && (availability.First() as Shift).Active)
                    {
                        if ((availability.First() as Shift).Slot == 1)
                        {
                            Shift1 = (Shift)availability.First();
                            Shift2 = (Shift)availability.Last();
                        }
                        else
                        {
                            Shift2 = (Shift)availability.First();
                            Shift1 = (Shift)availability.Last();
                        }
                    }
                    else
                    {
                        Shift1 = (Shift)availability.First();
                        Shift2 = (Shift)availability.Last();
                    }

                }
                else
                {
                    this.Shift1 = (Shift)availability.First();
                    //if (this.Shift1.Active && this.Shift1.ID == 0)
                    //{
                    //    this.Shift1.Slot = 1;
                    //}

                    this.Shift2 = null;
                }




                // ALMENO UNO SHIFT DEVE ESISTE
                //this.Shift1 = (Shift)availability.First();
                //if (this.Shift1.Active && this.Shift1.ID == 0)
                //{
                //    this.Shift1.Slot = 1;
                //}

                //if (availability.Count > 1)
                //{
                //    this.Shift2 = (Shift)availability.Last();
                //    if (this.Shift2.Active && this.Shift2.ID == 0)
                //    {
                //        this.Shift2.Slot = 2;
                //    }
                //}
                //else
                //{
                //    this.Shift2 = null;
                //}

                MessagingCenter.Send(new AvailabilityModifyMessage { Date = date, Shift1 = this.Shift1, Shift2 = this.Shift2 }, "AvailabilityShifts");
            }
            }
        }

        this.IsBusy = false;
    }

Answers

Sign In or Register to comment.