turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
781 stars 126 forks source link

Error using Butterknife #74

Closed easycheese closed 7 years ago

easycheese commented 7 years ago

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

easycheese commented 7 years ago

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.

turing-tech commented 7 years ago

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)?

easycheese commented 7 years ago

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.

turing-tech commented 7 years ago

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.

turing-tech commented 7 years ago

Let me know how it works.

easycheese commented 7 years ago

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.

turing-tech commented 7 years ago

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.

easycheese commented 7 years ago

Hey great, thanks!