Error using Butterknife
Closed this issue · 8 comments
The scrollbar is calling the following:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.support.v7.widget.RecyclerView$Adapter.getItemCount()' on a null object reference
at com.turingtechnologies.materialscrollbar.ScrollingUtilities.getCurScrollState(ScrollingUtilities.java:146)
After Butterknife unbinder is called resulting in an NPE. I didn't have this issue on 9.0.2
I don't have this problem on 9.3.0 either, was attempting to upgrade but had to switch from the
new DragScrollBar(getContext(), recyclerView, false);
Implementation to the xml implementation.
The error suggests that the recyclerView doesn't have an adapter at the time when the bar is being drawn. Have you set the adapter in the onCreate method (or whatever the analogous method is for fragments if that's the case)?
I set it later actually, because my data loads later and adapter actions depend on what is returned from a server. I don't think the library should cause a crash just because an adapter isn't attached until a later time period.
Whatever floats your boat then. I'll add back the programmatic route, but it won't have the formatting support like it used to. You'll need to add all of the layout constraints manually. Should only be a few lines though.
Let me know how it works.
Eh, I just use one line :)
new DragScrollBar(getContext(), recyclerView, false);
Could you not just add a check to see if the adapter exists before running code on it? I would prefer the XML if it has additional features.
Or perhaps a manual, addAdapter method.
It doesn't really have any additional features, and I'm avoiding doing that because it prevents the scroll bar from doing setup things that it needs to do (for example, figuring out if it should hide because there are too few elements for scrolling). Anyway, the new update should work for what you need.
Hey great, thanks!