Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer exception in design view #51

Open
karunanaik opened this issue Feb 27, 2017 · 2 comments
Open

Null pointer exception in design view #51

karunanaik opened this issue Feb 27, 2017 · 2 comments

Comments

@karunanaik
Copy link

java.lang.NullPointerException   at com.futuremind.recyclerviewfastscroll.RecyclerViewScrollListener.updateHandlePosition(RecyclerViewScrollListener.java:47)   at com.futuremind.recyclerviewfastscroll.FastScroller.onLayout_Original(FastScroller.java:168)   at com.futuremind.recyclerviewfastscroll.FastScroller.onLayout(FastScroller.java:-1)   at android.view.View.layout(View.java:17520)   at android.view.ViewGroup.layout(ViewGroup.java:5612)   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)   at android.view.View.layout(View.java:17520)   at android.view.ViewGroup.layout(ViewGroup.java:5612)   at android.support.constraint.ConstraintLayout.onLayout_Original(ConstraintLayout.java:1127)   at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:-1)   at android.view.View.layout(View.java:17520)   at android.view.ViewGroup.layout(ViewGroup.java:5612)   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)   at android.widget.FrameLayout.onLayout(FrameLayout.java:261)   at android.view.View.layout(View.java:17520)   at android.view.ViewGroup.layout(ViewGroup.java:5612)   at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)   at android.view.View.layout(View.java:17520)   at android.view.ViewGroup.layout(ViewGroup.java:5612)

I get the above null pointer exception in my design view.

Below is my xml:

`

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

    <com.futuremind.recyclerviewfastscroll.FastScroller
        android:id="@+id/fastScroller"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:orientation="vertical"
        app:fastscroll__bubbleColor="@color/colorGold"
        app:fastscroll__bubbleTextAppearance="@style/StyledScrollerTextAppearance"/>

</RelativeLayout>`

Can you please help me and let me know what am I missing here?

@ozv101
Copy link

ozv101 commented May 21, 2017

@karunanaik It's some bug with onLayout. It thinks the RecyclerView has been set. Found a work around: create your own CustomFastScroller extends FastScroller, then override onLayout:

 @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        if (recyclerView != null) {
            super.onLayout(changed, l, t, r, b);
        }
    }

Also,

@Override
    public void setRecyclerView(RecyclerView recyclerView) {
        this.recyclerView = recyclerView;
        super.setRecyclerView(recyclerView);

        requestLayout();
    }

then call setRecyclerView on your CustomFastScroller.

@kalyanimvn
Copy link

I got same error.But i fixed by using above code.The below code working fine.Thanks
@OverRide
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (recyclerView != null) {
super.onLayout(changed, l, t, r, b);
}
}
Also,

@OverRide
public void setRecyclerView(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
super.setRecyclerView(recyclerView);

    requestLayout();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants