I am trying to get and set a boolean through Sharedpreferences. The following code perfectly works on Marshmallow but not on Lolipop (5.0.1) - I get an exception: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean when I call getintroStatus()
Any help?
public void setIntrodone(boolean status) {
editor = settings.edit();
editor.putBoolean("intro_done_boolean", status);
editor.commit();
}
public boolean getintroStatus() {
try {
return settings.getBoolean("intro_done_boolean", false);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
Logcat Error:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.SharedPreferencesImpl.getBoolean(SharedPreferencesImpl.java:263)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at io.authme.home.MitroApplication.getintroStatus(MitroApplication.java:107)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at io.authme.home.MainActivity.onCreate(MainActivity.java:81)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.Activity.performCreate(Activity.java:6285)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.ActivityThread.access$900(ActivityThread.java:154)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.os.Looper.loop(Looper.java:148)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5490)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at java.lang.reflect.Method.invoke(Native Method)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-20 14:06:59.438 1401-1401/io.authme.home W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)