Open crazybee0909 opened 9 years ago
I had this issue but then realized I wasn't using the fastscroller on all recyclerview fragments that had it in the list.
So the fix (for me at least): Make sure you use the fastscroller in all fragments that use the layout with it. If you'd like to only use the fast scroller in only one of the fragments but not another then make another layout for it just with the fast scroller addded.
I got the same exception. I used fastScroller only in 1 layout, so "fix tip" of @ThatKawaiiGuy doesn`t work for me
XML of my Activity :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
>
<include layout="@layout/view_toolbar_main"
android:id="@+id/tbToolbar" />
<android.support.v7.widget.RecyclerView
android:id="@+id/lvContactsList"
android:layout_below="@+id/tbToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/vBottomSection"
/>
<xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
android:id="@+id/fast_scroller"
android:layout_width="@dimen/general_mid"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/lvContactsList"
android:layout_alignBottom="@+id/lvContactsList"
/>
<ProgressBar
android:id="@+id/pbProgressBar"
android:layout_width="@dimen/general_xx_large"
android:layout_height="@dimen/general_xx_large"
android:visibility="visible"
android:layout_centerInParent="true"
/>
<include layout="@layout/view_bottom_sheet_header"
android:id="@+id/vBottomSection"
android:layout_height="@dimen/general_x_large"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
in my Activity OnCreateMethod:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
contactsAdapter = /* code of adapter creation */
lvContactsList = findViewById(R.id.lvContactsList) as RecyclerView
lvContactsList.adapter = contactsAdapter
val lManager = LinearLayoutManager(this@KnownContactsActivity)
lManager.orientation = LinearLayoutManager.VERTICAL
lvContactsList.layoutManager = lManager
lvContactsList.apply {
adapter = contactsAdapter
}
fastScroller = findViewById(R.id.fast_scroller) as VerticalRecyclerViewFastScroller
fastScroller.setRecyclerView(lvContactsList)
lvContactsList.setOnScrollListener(fastScroller.onScrollListener)
progressBar.hide()
}
If I remove FastScroller -> all code works fine without crashing...
@ThatKawaiiGuy your advise is workable,but i think it is still a bug of this libary,not every fragment need to decorate for the recyclerview inside.
This might be a small issue but I'm not able to get past this. My fragment gives a null pointer exception like- Attempt to invoke virtual method 'android.support.v7.widget.RecyclerView$LayoutManager android.support.v7.widget.RecyclerView.getLayoutManager()' on a null object reference
This is my onCreateView of the fragment -
I can't figure out what is going wrong. Any ideas how to fix this minor issue?