timusus / RecyclerView-FastScroll

A simple FastScroller for Android's RecyclerView
Other
1.39k stars 183 forks source link

java.lang.ArithmeticException: divide by zero #69

Closed rnitame closed 6 years ago

rnitame commented 6 years ago
java.lang.ArithmeticException: divide by zero
               at com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView.scrollToPositionAtProgress(FastScrollRecyclerView.java:297)
               at com.simplecityapps.recyclerview_fastscroll.views.FastScroller.handleTouchEvent(FastScroller.java:205)
               at com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView.handleTouchEvent(FastScrollRecyclerView.java:138)
               at com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView.onTouchEvent(FastScrollRecyclerView.java:118)
               at android.support.v7.widget.RecyclerView.dispatchOnItemTouch(RecyclerView.java:2756)
               at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2899)
 override fun getSectionName(position: Int): String =
            sections[getSectionForAdapterPosition(position)].name

This error happen when scrolling. Is there a any solution?

G00fY2 commented 6 years ago

Seems like this (Line 402 in FastScrollRecyclerView) returns 0 in your RecyclerView which is not expected:

stateOut.rowHeight = child.getHeight() + getLayoutManager().getTopDecorationHeight(child) + getLayoutManager().getBottomDecorationHeight(child);

Because this height is the divider in Line 297 where your error occurs.

rnitame commented 6 years ago

@G00fY2

I got it. Is there a workaround for using multiple ViewTypes?

G00fY2 commented 6 years ago

I don't think so. Unfortunately this means that this implementation is also not working properly with sticky header libraries e.g.

rnitame commented 6 years ago

I see.

Unfortunately this means that this implementation is also not working properly with sticky header libraries e.g.

Should I make this issue separately? (By the way, I use https://github.com/ShamylZakariya/StickyHeaders )

rnitame commented 6 years ago

@G00fY2 How about this? https://github.com/timusus/RecyclerView-FastScroll/issues/69#issuecomment-355200068

G00fY2 commented 6 years ago

Relates to #42. There is no "easy" way to support this. Also haven't seen a Google app which has this feature. They use another approach.

Also unfortunately @timusus seems to currently not maintain the library.:cry:

timusus commented 6 years ago

I'll happily consider your PR.

G00fY2 commented 6 years ago

I would appreciate it if you could deploy the last changes in the meantime. Will may try to look into extending support for variable item sizes.

timusus commented 6 years ago

@rnitame

Is there a workaround for using multiple ViewTypes?

Yes, see the MeasurableAdapter interface in the Readme.

rnitame commented 6 years ago

@timusus I see. Thanks!

timusus commented 6 years ago

This divide by zero exception seems to occur if you have zero-height items in your adapter. I'm not sure when this would ever be the case..

If you do have zero-height items in your adapter, then you need to implement MeasurableAdapter in your RecyclerViewAdapter, and provide the heights of your views, so the FastScrollRecyclerView can draw the itself accurately.

I can't reproduce this issue with the MeasurableAdapter implemented.

rnitame commented 6 years ago

FYI, I fixed this issue what I increment a version without more development 👍