Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when call toggle() in inital state. #22

Open
HubertWo opened this issue Nov 6, 2016 · 1 comment
Open

NPE when call toggle() in inital state. #22

HubertWo opened this issue Nov 6, 2016 · 1 comment

Comments

@HubertWo
Copy link

HubertWo commented Nov 6, 2016

What I am trying to do: set switch state to PRESS right after application starts.
Every time I get Null Pointer Exception, because switch is in INIT state.

How to reproduce bug:

protected void onCreate(Bundle savedInstanceState) {

  if (shouldBeOn && !materialAnimatedSwitch.isChecked()) {
    materialAnimatedSwitch.toggle();
  }

}

Cause:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.animation.ValueAnimator.start()' on a null object reference
at
com.github.glomadrian.materialanimatedswitch.painter.BallPainter.setState(BallPainter.java:108)
at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.setState(MaterialAnimatedSwitch.java:139)
at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.doActionDown(MaterialAnimatedSwitch.java:164)
at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.toggle(MaterialAnimatedSwitch.java:178)`

@githubdoramon
Copy link

Use #17 solution for now... I did the same.... But it should be a way to set initial state

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

No branches or pull requests

2 participants