pwittchen / prefser

Wrapper for Android SharedPreferences with object serialization and RxJava Observables
Apache License 2.0
228 stars 26 forks source link

Boolean cannot be cast to java.lang.String #132

Open pranavlathigara opened 5 years ago

pranavlathigara commented 5 years ago

I have getting error while fetching boolean value in kotlin

val isAutoStart : Boolean? = PrefInstance.get(context)?.get(Constants.PREF_SERVICE_IS_ALERT,Boolean::class.java ,false)

Error Log

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String at android.app.SharedPreferencesImpl.getString(SharedPreferencesImpl.java:225) at com.github.pwittchen.prefser.library.Prefser.get(Prefser.java:266) at com.github.pwittchen.prefser.library.Prefser.get(Prefser.java:239)

pwittchen commented 5 years ago

Hi @pranavlathigara,

Thanks for reporting this issue. I'll have a look on that.

Regards, Piotr

ubuntudroid commented 5 years ago

@pranavlathigara Fix is simple: just use Boolean::class.javaObjectType instead of Boolean::class.java and you should be set.

pranavlathigara commented 5 years ago

ok let me try