material-animated-switch icon indicating copy to clipboard operation
material-animated-switch copied to clipboard

NPE when call toggle() in inital state.

Open HubertWo opened this issue 9 years ago • 1 comments

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)`

HubertWo avatar Nov 06 '16 10:11 HubertWo

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

githubdoramon avatar Apr 26 '17 01:04 githubdoramon