viliamvolosv / material-animated-switch

A material Switch with icon animations and color transitions
14 stars 2 forks source link

Null pointer exception when setting it to checked in recyclerview #1

Open AkshayPathak opened 7 years ago

AkshayPathak commented 7 years ago

Hi there, The fork you created seems to be working well, however I am having a null pointer exception when setting the switch through a recyclerview. I tried forking it and made this update but did not work. You can take a look at it here: https://github.com/AkshayPathak/material-animated-switch/commit/1a10028c3ad105d5353f036a5b4c786c77f044f7.

So instead I tried doing a check like this:

if (isSwitchEnabled && !holder.switchIsEnabled.
    holder.switchIsEnabled.toggle();
} else if (!isSwitchEnabled && holder.switchIsEnabled.isChecked()) {
     holder.switchIsEnabled.toggle();
}

but this is giving me this exception:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.nineoldandroids.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:152)
                                                                       at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.doActionDown(MaterialAnimatedSwitch.java:182)
                                                                       at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.toggle(MaterialAnimatedSwitch.java:198)
                                                                       at com.manage.parent.Modes.ModesContentItem.bindView(ModesContentItem.java:77)
                                                                       at com.manage.parent.Modes.ModesContentItem.bindView(ModesContentItem.java:27)
                                                                       at com.mikepenz.fastadapter.FastAdapter$OnBindViewHolderListenerImpl.onBindViewHolder(FastAdapter.java:1971)
                                                                       at com.mikepenz.fastadapter.FastAdapter.onBindViewHolder(FastAdapter.java:624)
                                                                       at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6389)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5335)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5598)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5440)
                                                                       at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5436)
                                                                       at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2224)
                                                                       at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1551)
                                                                       at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1511)
                                                                       at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:595)
                                                                       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3583)
                                                                       at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3025)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                       at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                       at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1658)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                       at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                       at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                       at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                       at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                       at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                       at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                       at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                       at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                                       at android.view.View.measure(View.java:17547)
                                                                       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)

I would be grateful if you could suggest a fix.

Thanks

viliamvolosv commented 7 years ago

Sorry man, cant help you right now. Not working with android now. If you find resolution for this issue, i can asscept accept pull request. After all i suguest for you find other component - this is old and abandoned