turing-tech / MaterialScrollBar

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

NullPointerException: Attempt to invoke virtual method 'int android.view.View.getTop()' on a null object reference #80

Closed pro100svitlo closed 7 years ago

pro100svitlo commented 7 years ago

here is log:

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getTop()' on a null object reference
android.support.v7.widget.RecyclerView$LayoutManager.getDecoratedTop (RecyclerView.java:8153)
com.turingtechnologies.materialscrollbar.ScrollingUtilities.getCurScrollState (ScrollingUtilities.java:152)
com.turingtechnologies.materialscrollbar.ScrollingUtilities.scrollToPositionAtProgress (ScrollingUtilities.java:107)
com.turingtechnologies.materialscrollbar.MaterialScrollBar.onDown (MaterialScrollBar.java:636)
com.turingtechnologies.materialscrollbar.DragScrollBar$1.onTouch (DragScrollBar.java:74)
android.view.View.dispatchTouchEvent (View.java:8470)

here is how activity looks like:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
...
        mDragScrollBar.addIndicator(mAlphabetIndicator, true);
        mDragScrollBar.setDraggableFromAnywhere(true);
    }

here is layout:

<RelativeLayout
    android:id="@android:id/content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <com.turingtechnologies.materialscrollbar.DragScrollBar
        android:layout_width="wrap_content"
        app:msb_recyclerView="@android:id/list"
        app:msb_lightOnTouch="false"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        app:msb_handleColour="@color/colorAccent"
        app:msb_barColour="@android:color/white"
        app:msb_handleOffColour="@color/colorPrimaryDark"
        app:msb_textColour="@android:color/white"
        />

    <include
        layout="@layout/item_progress_bar"
        />

    <include
        layout="@layout/item_list_empty_view"
        />
</RelativeLayout>

please add some npe try catch ;-)

turing-tech commented 7 years ago

Could you verify which lib version you're using real quick?

pro100svitlo commented 7 years ago

I am sorry ) It was pretty old one, 10.+ Will try the last one! Thanks for this lib :)

turing-tech commented 7 years ago

Np :)