Weird exception: Cannot cast String to Boolean when using getBoolean Weird exception: Cannot cast String to Boolean when using getBoolean android android

Weird exception: Cannot cast String to Boolean when using getBoolean


If there's ever been a string with that key, even if by accident, it will stay there until you clear the app's data or uninstall. Try uninstalling it to see if it still occurs.


The exception occurs in this Android method:

public boolean getBoolean(String key, boolean defValue) {    synchronized (this) {        awaitLoadedLocked();        Boolean v = (Boolean)mMap.get(key); // On this line        return v != null ? v : defValue;    }}

The only sense I can make of this error is that your are reusing the key IntroActivity.SHOW_INTRO for a String somewhere else in your code.


I am assuming that

sp.getBoolean(IntroActivity.SHOW_INTRO, true)// this line returns a String value.

so you can do like this

boolean showIntro = Boolean.parseBoolean(sp.getBoolean(IntroActivity.SHOW_INTRO, true));