# Crash in ChannelListFragment

**URL:** <https://community.sendbird.com/t/crash-in-channellistfragment/3865>\
**Category:** Android\
**Tags:** group-channel, chatsdk\
**Created:** [January 30, 2022, 4:36pm UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865 "2022-01-30T16:36:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladislav\_Karpman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/vladislav_karpman/32/1860_2.png) [@Vladislav\_Karpman](https://community.sendbird.com/u/Vladislav_Karpman)\
**Post date:** [January 30, 2022, 4:36pm UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/1 "2022-01-30T16:36:25Z")

</div>

Hi!

I use the latest version of UIKit (com.sendbird.sdk:uikit:2.2.3), and I have crash in production when user switches between `ChannelListFragment` and other fragment a bit fast than regular user.

This the log of the crash:

```auto
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: health.alike.app, PID: 11531
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.sendbird.android.handlers.GroupChannelCollectionHandler.onChannelsUpdated(com.sendbird.android.handlers.GroupChannelContext, java.util.List)' on a null object reference
        at com.sendbird.android.GroupChannelCollection$7.run(GroupChannelCollection.java:542)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

```

Likely it happens inside `ChannelListViewModel`.

Also, I noticed that when a user switches between fragments a bit faster `initChannelCollection()` and `disposeChannelCollection()` don’t go one after another as they supposed to. Hence, I think that’s why crash appears:

```auto
D/SBUIKIT: [19:21:11.812 ChannelListViewModel:initChannelCollection():36] >> ChannelListViewModel::initChannelCollection()
D/SBUIKIT: [19:21:11.959 ChannelListViewModel:initChannelCollection():36] >> ChannelListViewModel::initChannelCollection()
D/SBUIKIT: [19:21:12.292 ChannelListViewModel:disposeChannelCollection():45] >> ChannelListViewModel::disposeChannelCollection()
D/SBUIKIT: [19:21:12.745 ChannelListViewModel:disposeChannelCollection():45] >> ChannelListViewModel::disposeChannelCollection()

```

Normal call stack is supposed to look like this:

```auto
D/SBUIKIT: [19:32:46.707 ChannelListViewModel:initChannelCollection():36] >> ChannelListViewModel::initChannelCollection()
D/SBUIKIT: [19:32:48.123 ChannelListViewModel:disposeChannelCollection():45] >> ChannelListViewModel::disposeChannelCollection()
D/SBUIKIT: [19:32:49.775 ChannelListViewModel:initChannelCollection():36] >> ChannelListViewModel::initChannelCollection()
D/SBUIKIT: [19:32:50.848 ChannelListViewModel:disposeChannelCollection():45] >> ChannelListViewModel::disposeChannelCollection()

```

---

<div class="post-metadata">

**Author:** ![Woo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/woo/32/125_2.png) [@Woo](https://community.sendbird.com/u/Woo)\
**Post date:** [January 31, 2022, 8:13am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/2 "2022-01-31T08:13:20Z")

</div>

@Vladislav_Karpman thanks for the reporting! I will let our android team to know and get back to you soon

---

<div class="post-metadata">

**Author:** ![Vladislav\_Karpman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/vladislav_karpman/32/1860_2.png) [@Vladislav\_Karpman](https://community.sendbird.com/u/Vladislav_Karpman)\
**Post date:** [January 31, 2022, 10:28am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/3 "2022-01-31T10:28:23Z")

</div>

@Woo It’s a pretty much important since we’re having crash in production.  
Hopefully, soon you will find a solution

---

<div class="post-metadata">

**Author:** ![LeoShin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/leoshin/32/397_2.png) [@LeoShin](https://community.sendbird.com/u/LeoShin)\
**Post date:** [February 3, 2022, 12:56am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/4 "2022-02-03T00:56:51Z")

</div>

@Vladislav_Karpman Thank you for reporting!.

- NPE problem has been fixed, and it will be released next regular release.

And regarding the problem of order, there are two cases where A is disposed.

- If an existing collection exists when trying to retrieve a channel list through the loadInitial, previous collection will dispose
- If the View Model is clear, it is disposed.  
So please check if `loadInitial` is being called twice in a row.

---

<div class="post-metadata">

**Author:** ![Vladislav\_Karpman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/vladislav_karpman/32/1860_2.png) [@Vladislav\_Karpman](https://community.sendbird.com/u/Vladislav_Karpman)\
**Post date:** [February 3, 2022, 9:16am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/5 "2022-02-03T09:16:33Z")

</div>

@LeoShin Thanks!  
Hopefully the issue is resolved.

Regarding your comment:  
`loadInitial()` is private method and is under UIKit control, so you have to make sure that order is correct.

---

<div class="post-metadata">

**Author:** ![LeoShin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/leoshin/32/397_2.png) [@LeoShin](https://community.sendbird.com/u/LeoShin)\
**Post date:** [February 3, 2022, 11:52am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/6 "2022-02-03T11:52:41Z")

</div>

> [@Vladislav\_Karpman](#):
>
> ```auto
> D/SBUIKIT: [19:21:11.812 ChannelListViewModel:initChannelCollection():36] >> ChannelListViewModel::initChannelCollection()
> D/SBUIKIT: [19:21:11.959 ChannelListViewModel:initChannelCollection():36] >> ChannelListViewModel::initChannelCollection()
> D/SBUIKIT: [19:21:12.292 ChannelListViewModel:disposeChannelCollection():45] >> ChannelListViewModel::disposeChannelCollection()
> D/SBUIKIT: [19:21:12.745 ChannelListViewModel:disposeChannelCollection():45] >> ChannelListViewModel::disposeChannelCollection()
> 
> ```

**loadInitial** , which I mentioned above, is a method of the ChannelListViewModel, which is a public method.  
Since the initChannelCollection from the log is called only when **loadInitial** is called, I was wondering when **loadInitial** is called.  
How can I reproduce what’s shown in the log?

---

<div class="post-metadata">

**Author:** ![Vladislav\_Karpman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/vladislav_karpman/32/1860_2.png) [@Vladislav\_Karpman](https://community.sendbird.com/u/Vladislav_Karpman)\
**Post date:** [February 3, 2022, 4:49pm UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/7 "2022-02-03T16:49:38Z")

</div>

I have 2 fragments:  
One is just regular fragment from our app and another one is ChannelListFragment.

If I start switching between these 2 fragments pretty fast, I will get error pretty soon.

---

<div class="post-metadata">

**Author:** ![LeoShin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/leoshin/32/397_2.png) [@LeoShin](https://community.sendbird.com/u/LeoShin)\
**Post date:** [February 4, 2022, 12:21am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/8 "2022-02-04T00:21:50Z")

</div>

We will include this in the regular release. The regular release will be around mid-February.

---

<div class="post-metadata">

**Author:** ![Vladislav\_Karpman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/vladislav_karpman/32/1860_2.png) [@Vladislav\_Karpman](https://community.sendbird.com/u/Vladislav_Karpman)\
**Post date:** [February 6, 2022, 8:38am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/9 "2022-02-06T08:38:33Z")

</div>

Thanks, hopefully it will be fixed

---

<div class="post-metadata">

**Author:** ![LeoShin](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/leoshin/32/397_2.png) [@LeoShin](https://community.sendbird.com/u/LeoShin)\
**Post date:** [February 17, 2022, 9:03am UTC](https://community.sendbird.com/t/crash-in-channellistfragment/3865/10 "2022-02-17T09:03:42Z")

</div>

We have released v2.2.4 uikit that fixed this issue today. please check it out. hopefully, it will have been fixed.
