SimplicityApks / ReminderDatePicker

A Google Keep-like Date and Time Picker for reminders
Apache License 2.0
74 stars 26 forks source link

A lot of users are getting ClassCastException #19

Closed chrisonline closed 9 years ago

chrisonline commented 9 years ago

A lot of users are reporting crashes.

The crash is always from this cast: final TimeItem selectedItem = (TimeItem) getSelectedItem();

I get a ClassCastException.

java.lang.ClassCastException: com.simplicityapks.reminderdatepicker.lib.r cannot be cast to com.simplicityapks.reminderdatepicker.lib.n at com.simplicityapks.reminderdatepicker.lib.TimeSpinner.getSelectedTime(TimeSpinner.java:150) at com.simplicityapks.reminderdatepicker.lib.ReminderDatePicker.getSelectedDate(ReminderDatePicker.java:188) at com.simplicityapks.reminderdatepicker.lib.ReminderDatePicker.onItemSelected(ReminderDatePicker.java:378) at com.simplicityapks.reminderdatepicker.lib.e.onItemSelected(PickerSpinner.java:178)

But I can't reproduce. Any help/idea why this can happens sometime? I got it myself once after rotating the screen, but after I wanted to reproduce it does not happen anymore :-(

SimplicityApks commented 9 years ago

I know what you're talking about since that specific crash has happened to me several times during development of this library. It occurs when the user selects/creates a temporary item and the system calls the onItemSelected listener when the temporary item is not yet in place or somehow the internal setSelection call does not get through. The problem here is that the platform behaviour is not specified as using these temporary items in the Spinner is quite a hack. Therefore an older Android version or even a different manufactorer version could behave differently. So it would be helpful if there was some kind of pattern in the users that get it like everyone on Android 2.3 or so.

Another time this crash can occur is during initialization, depending on which flags you use. So could you please let me know in what order and in which activity callback (onCreate, onResume, etc.) your app calls one of the setter methods, especially any setFlags() and setSelection() calls.

I'll have a look at it when I get the time, maybe I'll surround that cast statement with a catch block and throw some logs, but I don't know in what state the UI will be at that point (the right item will probably not be selected...)

chrisonline commented 9 years ago

SetFlags() and setSelection() is not used in my code. I call setSelectedDate() in the onCreate() method.

SimplicityApks commented 9 years ago

Mmmh well setSelectedDate() calls setSelection() so that might be it. I will try to take a look at it when I have time, but I can't really promise anything because it is quite hard to reproduce, as I won't be testing this on every Android version out there without evidence for an issue there.

chrisonline commented 9 years ago

OK thanks. I will try in the meantime to catch it.

Here is a statistic about crashes with OS and phone: crash

SimplicityApks commented 9 years ago

Finally got the time and figured out what was wrong: It happened during rotation! Now this shouldn't happen again, as the callbacks are ignored when the footer is selected. However, I noticed that during rotation the onItemSelected callback is still fired twice, first with position 0 and then with the right element. I am not sure if that's a problem, but I'm leaving it like that for now.

chrisonline commented 9 years ago

Thanks for the great support!!! Will let you know if the double selection is a problem.

SimplicityApks commented 9 years ago

Closed for 1.2 release.