0

I'm trying to do TimePickerPreferences and I tried accepted answer and second answer in the question. And I got following error when I call persistString(time) function at onDialogClosed

FATAL EXCEPTION: main
 Process: com.foo.example, PID: 29414
 java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
     at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:225)
     at android.preference.Preference.getPersistedString(Preference.java:1472)
     at android.preference.Preference.persistString(Preference.java:1441)
     at com.foo.example.ui.preferences.TimePreference.onDialogClosed(TimePreference.java:60)
     at android.preference.DialogPreference.onDismiss(DialogPreference.java:395)
     at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1323)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:148)
     at android.app.ActivityThread.main(ActivityThread.java:5417)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Community
  • 1
  • 1
melomg
  • 737
  • 3
  • 20
  • 39
  • please show Your relevant part of code... – Opiatefuchs Apr 05 '16 at 11:49
  • 1
    obviously you should clear the preferences(by uninstalling the app fx) before using one solution after another ... one solution is using int to store the date and another using the string ... if you used the same key it could throw such error – Selvin Apr 05 '16 at 11:54
  • that's exactly what happened in my case. I changed the key for now and it is working. Thank you so much @Selvin – melomg Apr 05 '16 at 12:09

0 Answers0