singhangadin/android-toggle

Exception when change state on/off

Closed this issue · 1 comments

Hi,

I tried your wonderfull toggle button on my a demo app but I have some trouble when clicking it :

java.lang.BootstrapMethodError: Exception from call site #6 bootstrap method
at com.github.angads25.toggle.widget.LabeledSwitch.performClick(LabeledSwitch.java:355)
at com.github.angads25.toggle.widget.LabeledSwitch.onTouchEvent(LabeledSwitch.java:409)
at android.view.View.dispatchTouchEvent(View.java:12529)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:452)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1836)
at android.app.Activity.dispatchTouchEvent(Activity.java:3400)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:410)
at android.view.View.dispatchPointerEvent(View.java:12768)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5127)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4930)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4447)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4500)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4466)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4606)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4474)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4663)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4447)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4500)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4466)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4474)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4447)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7124)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7093)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7054)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7227)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:187)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:178)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7198)
2018-11-19 16:18:54.983 14675-14675/com.test.demo E/AndroidRuntime: at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7250)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1004)
at android.view.Choreographer.doCallbacks(Choreographer.java:816)
at android.view.Choreographer.doFrame(Choreographer.java:745)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:990)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:280)
at android.app.ActivityThread.main(ActivityThread.java:6710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: Bootstrap method returned null

If seems that "switchColor.addUpdateListener(animation -> {" on line 365 return null.
This the code in the layout:

<com.github.angads25.toggle.widget.LabeledSwitch
    android:id="@+id/option_classifier_enabled"
    android:layout_width="80dp"
    android:layout_height="30dp"
    android:textSize="14sp"
    app:colorBorder="@color/colorAccent"
    app:layout_column="1"
    app:layout_gravity="center_vertical"
    app:layout_row="0"
    app:on="false"
    app:textOff="No"
    app:textOn="Yes" />

I used you compoment in a fragment. It displays correctly but this error occured when clicking on it.

If you have any idea about what's append.

Thanks in advance,

Best regards

Dear Angad,

First I apologize because I forgot to thk u for your wonderfull work.
I solve my problem by moving the listener code on an outside declaration.

        switchColor.addUpdateListener(animation -> {
            float value = (float) animation.getAnimatedValue();
            thumbBounds.set(value, thumbBounds.top, value + thumbRadii, thumbBounds.bottom);
            invalidate();
        });

now

private ValueAnimator.AnimatorUpdateListener AnimatorListener = new ValueAnimator.AnimatorUpdateListener() {
@OverRide
public void onAnimationUpdate(ValueAnimator animation) {
float value = (float) animation.getAnimatedValue();
thumbBounds.set(value, thumbBounds.top, value + thumbRadii, thumbBounds.bottom);
invalidate();
}
};
switchColor.addUpdateListener(AnimatorListener);

Even if I still wonder why it works with your demo app and not with mine :)

Have a great day