From 1681aa3d220ab3f1aab5b79447d2d3b9d7410ce8 Mon Sep 17 00:00:00 2001 From: Uday Srinath Date: Tue, 14 Nov 2017 15:55:17 -0800 Subject: [PATCH] Fix NPE in onRestoreInstanceState() for lastSelectedDay --- .../materialcalendarview/view/CalendarView.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java b/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java index 76d74ff..8b2fc6e 100644 --- a/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java +++ b/materialcalendarview/src/main/java/io/blackbox_vision/materialcalendarview/view/CalendarView.java @@ -262,15 +262,14 @@ protected void onRestoreInstanceState(Parcelable state) { currentMonthIndex = savedInstanceState.getInt(KEY_MONTH_INDEX); if (savedInstanceState.getSerializable(KEY_SELECTED_DATE) != null) { lastSelectedDay = (Date) savedInstanceState.getSerializable(KEY_SELECTED_DATE); + } else { + lastSelectedDay = new Date(); } } - Calendar calendar = (lastSelectedDay != null) ? getCalDate(lastSelectedDay) : Calendar.getInstance(Locale.getDefault()); + Calendar calendar = getCalDate(lastSelectedDay); update(calendar); - - if (lastSelectedDay != null) { - markDateAsSelected(lastSelectedDay); - onDateClickListener.onDateClick(lastSelectedDay); - } + markDateAsSelected(lastSelectedDay); + onDateClickListener.onDateClick(lastSelectedDay); } super.onRestoreInstanceState(state);