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

NullPointerException with null data in adapter #17

Closed
timothyjc opened this issue Feb 27, 2015 · 8 comments
Closed

NullPointerException with null data in adapter #17

timothyjc opened this issue Feb 27, 2015 · 8 comments

Comments

@timothyjc
Copy link

My data in my adapter is empty when the view is loaded and I get the following exception.

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference
at android.support.v7.widget.RecyclerView.getChildViewHolder(RecyclerView.java:2567)
at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress(VerticalLinearLayoutManagerScrollProgressCalculator.java:29)
at xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller.onLayout(AbsRecyclerViewFastScroller.java:202)
at android.view.View.layout(View.java:15596)
at android.view.ViewGroup.layout(ViewGroup.java:4966)

The problem is in VerticalLinearLayoutManagerScrollProgressCalculator:

@Override
public float calculateScrollProgress(RecyclerView recyclerView) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int lastFullyVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();

    View visibleChild = recyclerView.getChildAt(0);
    ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);

There is no child at index 0.

This method should handle the case when the RecyclerView has no children, such as when there is not yet any data.

@Maxr1998
Copy link

Maxr1998 commented Mar 8, 2015

Can confirm. This also applies when a using a filter with no results.

@Maxr1998
Copy link

Maxr1998 commented Apr 8, 2015

Fixed in master, please close.

@Komoi
Copy link

Komoi commented Apr 12, 2015

It seems still broken to me - It fails with same (similar) stacktrace when trying to use it with empty filtered adapter. I am using your lib via compile 'xyz.danoz:recyclerviewfastscroller:0.1.0' in gradle.

@Maxr1998
Copy link

Use the new 0.1.1 and report back ;)

@Komoi
Copy link

Komoi commented Apr 15, 2015

This fixes the issue, thank you for fast response :)

@Maxr1998
Copy link

@Komoi may I ask you what you did because I still get a crash on fastScroller.setRecyclerView()
It's a nullpointer exception, but I'm pretty sure the items aren't null :/
Look at my source: https://github.com/Maxr1998/MaxLock/blob/master/app/src/main/java/de/Maxr1998/xposed/maxlock/ui/settings/appslist/AppsListFragment.java#L131

Layout: https://github.com/Maxr1998/MaxLock/blob/master/app/src/main/res/layout-v14/fragment_appslist.xml

Don't mind the outcommented lines, they are no comments in my local sources..

@Komoi
Copy link

Komoi commented Apr 15, 2015

@Maxr1998 I actually implemented fast scroll without indicator, it seemed to hard to implement if fully for me, I got lost in examples explaining use of indicators. I checked your code and your problem might be unrelated to this issue and I really cant help you since I do not fully understand it. Is your backtrace similar as timothyjc's? Good luck with your project :)

@Maxr1998
Copy link

Thanks for looking into it :)
I don't believe the section indicator is the problem, I think I'll have to rewrite this whole stuff anyway...
Thanks and good luck for you too!

@danoz73 please close this issues as it's fixed.

@danoz73 danoz73 closed this as completed Apr 16, 2015
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

Successfully merging a pull request may close this issue.

4 participants