prefser icon indicating copy to clipboard operation
prefser copied to clipboard

Boolean cannot be cast to java.lang.String

Open pranavlathigara opened this issue 6 years ago • 3 comments

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)

pranavlathigara avatar Feb 22 '19 09:02 pranavlathigara

Hi @pranavlathigara,

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

Regards, Piotr

pwittchen avatar Feb 22 '19 11:02 pwittchen

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

ubuntudroid avatar May 20 '19 16:05 ubuntudroid

ok let me try

pranavlathigara avatar May 20 '19 17:05 pranavlathigara