Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

ClassCastException when calling get() on a LiveVariable in Editor mode #9

Closed
fingertricks opened this issue Apr 22, 2016 · 1 comment

Comments

@fingertricks
Copy link

fingertricks commented Apr 22, 2016

Apologies for duplication of an issue I've reported via the community forums, but I thought this might be the best place to report this issue I'm seeing.

When using the latest Android SDK (v1.4.2) and LiveVariables I see the following exception when calling get() on a LiveVariable when I'm in Editor or Preview mode:

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

Steps to reproduce:

  1. Navigate to the screen containing the experiment,
  2. Switch between variants in the Optimizely dashboard (which changes the LiveVariable from true to false or vice versa)
  3. navigate back to the previous screen
  4. return to the experiment screen again

I can workaround the problem with the following wrapper around the call to the get(), but it shouldn't be necessary:

private static LiveVariable<Boolean> enableLogosVariable = Optimizely.booleanForKey(HYGIENE_LOGOS, false);

public Boolean isExperimentVariantOn() {
    try {
        return enableLogosVariable.get();
    } catch (ClassCastException e) {
        return false;
    }
}
@fingertricks
Copy link
Author

This is fixed in v1.5.0 of the SDK, so closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant