Weird exception: Cannot cast String to Boolean when using getBoolean
Posted
by
La bla bla
on Stack Overflow
See other posts from Stack Overflow
or by La bla bla
Published on 2012-10-12T03:04:10Z
Indexed on
2012/10/12
3:37 UTC
Read the original article
Hit count: 231
I'm getting a very weird error.
I have 2 activities. On both I'm getting the SharedPreferences
using MODE_PRIVATE
(if it matters) by sp = getPreferences(MODE_PRIVATE);
on each activity's onCreate()
I'm calling sp.getBoolean(IntroActivity.SHOW_INTRO, true)
On the IntroActivity
this works fine. But when I'm trying in the main activity, I'm getting this
10-12 04:55:23.208: E/AndroidRuntime(11668): FATAL EXCEPTION: main
10-12 04:55:23.208: E/AndroidRuntime(11668): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:242)
10-12 04:55:23.208: E/AndroidRuntime(11668): at com.lablabla.parkme.ParkMeActivity$2.onClick(ParkMeActivity.java:194)
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.view.View.performClick(View.java:4084)
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.view.View$PerformClick.run(View.java:16966)
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.os.Handler.handleCallback(Handler.java:615)
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.os.Handler.dispatchMessage(Handler.java:92)
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.os.Looper.loop(Looper.java:137)
10-12 04:55:23.208: E/AndroidRuntime(11668): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-12 04:55:23.208: E/AndroidRuntime(11668): at java.lang.reflect.Method.invokeNative(Native Method)
10-12 04:55:23.208: E/AndroidRuntime(11668): at java.lang.reflect.Method.invoke(Method.java:511)
10-12 04:55:23.208: E/AndroidRuntime(11668): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-12 04:55:23.208: E/AndroidRuntime(11668): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-12 04:55:23.208: E/AndroidRuntime(11668): at dalvik.system.NativeStart.main(Native Method)
I made sure that I'm not putting a String
somewhere in the middle with that same key
Any ideas?
Thanks!
EDIT: some code:
//onCreate()
sp = getPreferences(MODE_PRIVATE);
// other method
boolean showIntro = sp.getBoolean(IntroActivity.SHOW_INTRO, true); // Exception is here
showIntroCheckBox.setChecked(showIntro);
If it matters, the code which throws the exception is inside a button's onClick
© Stack Overflow or respective owner