AdapterDelegates icon indicating copy to clipboard operation
AdapterDelegates copied to clipboard

[Crash] Null datasource when PagedList is null

Open avalanchas opened this issue 6 years ago • 2 comments

Currently we're seeing spurious crashes when using the PagedListDelegationAdapter

How to reproduce

Unclear, seems to happen when initialising a new adapter

Affected devices

All tested, some Pixels, some Samsung Galaxys

Version of library

4.2.0

Stacktrace

Relevant portion:

2019-11-03 15:21:28.783 ? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: at.radio.android, PID: 32618
    java.lang.NullPointerException: Items datasource is null!
        at com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager.getItemViewType(AdapterDelegatesManager.java:232)
        at com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter.getItemViewType(PagedListDelegationAdapter.java:93)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5926)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
...

Full stacktrace: https://gist.github.com/avalanchas/21f1965ed3ab425d05753bda1ff8fc43

As I read the Android docs, it's a general truth, that the getCurrentList method of a PagedList can be null at any point. So isn't it just the case, that we'll need to change this:

@Override
public int getItemViewType(int position) {
    return delegatesManager.getItemViewType(getCurrentList(), position);
}

to this:

@Override
public int getItemViewType(int position) {
    return getCurrentList() == null ? FALLBACK : delegatesManager.getItemViewType(getCurrentList(), position);
}

avalanchas avatar Nov 04 '19 09:11 avalanchas

Sorry for the very very late response. Is this still an issue or got resolved in the meantime?

sockeqwe avatar Apr 13 '20 17:04 sockeqwe

I am experiencing this issue when trying to add a fallback delegate for a PagedList.

I tried looking at the sample to see if there is some sort of example for the scenario where you want to display a loading listitem while a load from a datasource is in progress and while the sample has a loading delegate it is never used as far as I can see.

I was attempting to create a virtual item based on a signal from my datasource by overriding getItem/Count but it is surprisingly difficult to make happen. Altering the underlying data seems a bit irritating also so I might move the loading indicator outside of the list which will unfortunately look a bit weird, unless you have any insight into a solution?

After a bit more googling I think I am going to give MergeAdapter a shot, it should all play together.

macgills avatar May 18 '20 12:05 macgills