bgogetap / StickyHeaders

Easily add Sticky Headers to your RecyclerView
Apache License 2.0
521 stars 88 forks source link

Crash on FrameLayout layoutChildren #23

Open oiramcro opened 8 years ago

oiramcro commented 8 years ago

Recently I wrapped my RecyclerView with FrameLayout so I can use StickyHeaders. Since then from time to time I notice this strange crash. I extracted the log from Fabric. I can't reproduce it but I it could it's related to onNotifyDataSetChanged when data goes from N to 0 items and list was scrolled to the half height.

<android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/refreshView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/resultDateView">

            <FrameLayout
                android:layout_width="wrap_content"
                android:id="@+id/stickyHolder"
                android:layout_height="wrap_content">

                <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/live_rw_liveMatchList"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scrollbars="vertical" />

            </FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Fatal Exception: java.lang.NullPointerException
       at android.widget.FrameLayout.layoutChildren(FrameLayout.java:405)
       at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
       at android.view.View.layout(View.java:15749)
       at android.view.ViewGroup.layout(ViewGroup.java:4880)
       at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:596)
       at android.view.View.layout(View.java:15749)
       at android.view.ViewGroup.layout(ViewGroup.java:4880)

Do you know what is going on here ?

bgogetap commented 8 years ago

What line of code is being run at FrameLayout:line#405? (Not matching with the source I have, so just curious).

oiramcro commented 8 years ago

I guess FrameLayout code is different depending on which android version that user has ?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference at android.widget.FrameLayout.layoutChildren(FrameLayout.java:591) at android.widget.FrameLayout.onLayout(FrameLayout.java:574) at android.view.View.layout(View.java:16001) at android.view.ViewGroup.layout(ViewGroup.java:5181) at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:596)

You can see on this screenshot that it's kind of specific for every android version: https://www.dropbox.com/s/vw8kcv5u1kh48qy/Screen%20Shot%202016-10-01%20at%2008.59.09.png?dl=1

This started to happen once I wrapped my recycler view with framelayout, but I can't reproduce it.

bgogetap commented 8 years ago

Ok, I was able to reproduce it. Basically if the currently attached sticky header is removed from the dataset, this happens. Looking into a fix.

bgogetap commented 8 years ago

Fixed in 53e0449a79a8485a45f79ed05dd0cc53e96c9de6 (Version 0.3.4)

I would advise a reasonably thorough testing before pushing this out into an update, but this issue should be resolved. I think there is room for improvement in the way I'm holding onto header state, but this was a pretty big flaw so I wanted to get a preliminary fix out ASAP.

Thanks for reporting the issue!

utkarshGithub commented 7 years ago

issue still there

disparate commented 6 years ago

Issue can still be reproduced on v0.4.9

disparate commented 6 years ago

As a temporary hack you can use your own HackyFrameLayout class and catch NullPointerException inside the onLayout method.

bgogetap commented 6 years ago

Is there a reproducible set of actions I can try to recreate this issue or are you just seeing it in logs?

disparate commented 6 years ago

@bgogetap Sorry, haven't seen your reply. I was able to reproduce the issue always following this steps.

  1. Scroll recycler so the sticky header view is fixed at the top of the view.
  2. Change data for adapter (with following notifyDataSetChanged call() )
mitcho85 commented 5 years ago

Is there any update on this bug? @bgogetap thanks!

bgogetap commented 5 years ago

No update. I'd be happy to look into it if there is a repro I can examine, but it's not something I can blindly dig into right now.