sayyam / carouselview

A simple library to add carousel view in android app.
Apache License 2.0
1.15k stars 260 forks source link

Divide by 0 crash when setting page count to 0. #111

Open AnupKhanal opened 5 years ago

AnupKhanal commented 5 years ago

This happens when I increase the page count then I gradually decrease it to 0. I don't get this exception when i set page count to 1 and then back to 0. But if I set page count to more than that then i set it again to 0, i get this exception.

java.lang.ArithmeticException: divide by zero
    at com.synnapps.carouselview.CarouselView$SwipeTask$1.run(CarouselView.java:409)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7116)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)

Turns out the library is doing this which is causing the exception.

int nextPage = (containerViewPager.getCurrentItem() + 1) % getPageCount();

Byenkya commented 3 years ago

Is there a way to fix this bug?