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

[Crash] Null datasource when PagedList is null #78

Open
avalanchas opened this issue Nov 4, 2019 · 2 comments
Open

[Crash] Null datasource when PagedList is null #78

avalanchas opened this issue Nov 4, 2019 · 2 comments

Comments

@avalanchas
Copy link

avalanchas commented Nov 4, 2019

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);
}
@sockeqwe
Copy link
Owner

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

@macgills
Copy link

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.

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