# Getting crash almost all the time

**URL:** <https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585>\
**Category:** Android\
**Tags:** group-channel, chatsdk\
**Created:** [December 15, 2021, 9:21am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585 "2021-12-15T09:21:24Z")\
**Posts on this page:** 14\
**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:** [December 15, 2021, 9:21am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/1 "2021-12-15T09:21:24Z")

</div>

Hi, everybody.  
Started integrating the Sendbird android UIKit and faced with the following crash.  
When I send message to some user, then go back to ChannelsListFragment and then enter to the chat(ChannelFragment) I previously was, app always crashes.

This is the error I am getting:

```auto
 java.util.NoSuchElementException
        at java.util.TreeMap.key(TreeMap.java:1328)
        at java.util.TreeMap.firstKey(TreeMap.java:291)
        at java.util.TreeSet.first(TreeSet.java:394)
        at com.sendbird.uikit.model.MessageList.getLatestMessage(MessageList.java:201)
        at com.sendbird.uikit.vm.ChannelViewModel.getLatestMessage(ChannelViewModel.java:161)
        at com.sendbird.uikit.fragments.ChannelFragment.lambda$null$9$com-sendbird-uikit-fragments-ChannelFragment(ChannelFragment.java:478)
        at com.sendbird.uikit.fragments.ChannelFragment$$ExternalSyntheticLambda23.onListUpdated(Unknown Source:11)
        at com.sendbird.uikit.activities.adapter.MessageListAdapter.lambda$null$5$com-sendbird-uikit-activities-adapter-MessageListAdapter(MessageListAdapter.java:361)
        at com.sendbird.uikit.activities.adapter.MessageListAdapter$$ExternalSyntheticLambda5.run(Unknown Source:14)

```

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 16, 2021, 1:43am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/2 "2021-12-16T01:43:31Z")

</div>

Hi, Could you let me know the version of our chat SDK and UIKit SDK?

---

<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:** [December 16, 2021, 8:03am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/3 "2021-12-16T08:03:52Z")

</div>

I use this dependency:  
implementation ‘com.sendbird.sdk:uikit:2.2.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:** [December 19, 2021, 11:56am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/4 "2021-12-19T11:56:33Z")

</div>

Inside ChannelViewModel, SDK asks for latest messages, but list is empty.  
Because of the fact, that you use “first” method, the app getting crashed all the time

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 19, 2021, 11:39pm UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/5 "2021-12-19T23:39:55Z")

</div>

Do you use Chat SDK? only UIKit SDK?

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 19, 2021, 11:58pm UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/6 "2021-12-19T23:58:08Z")

</div>

- Did you customize ChannelFragment?

---

<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:** [December 20, 2021, 8:37am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/7 "2021-12-20T08:37:30Z")

</div>

I use UIKit SDK and yes I customized a bit ChannelFragment

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 20, 2021, 9:07am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/8 "2021-12-20T09:07:41Z")

</div>

How did you customize it?

---

<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:** [December 20, 2021, 12:26pm UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/9 "2021-12-20T12:26:15Z")

</div>

> [@Vladislav\_Karpman](#):
>
> ChannelFragment

```auto
return Builder(ChatChannelFragmentArgs.fromBundle(args).keyChannelUrl)
                .setUseHeader(false)
                .setUseInputLeftButton(false)
                .setCustomChannelFragment(ChatChannelFragment())
                .setMessageListAdapter(AlikeMessageListAdapter(avatarBitmapHelper) { view, userId ->
                    view.findNavController().navigate(MainNavigationDirections.actionGlobalToProfileFragment(userId, fromChat = true))
                })
                .build()
                .also {
                    args.putAll(it.arguments)
                }

```

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 21, 2021, 12:13am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/10 "2021-12-21T00:13:15Z")

</div>

I am trying to reproduce your issue. I cannot reproduce it…! ☹  
However, we add protection codes for this issue. It will be released this week.  
I will notice you when fixed version is released.

- If possible, Could you let me know reproduceable steps in detail?

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 21, 2021, 8:01am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/11 "2021-12-21T08:01:53Z")

</div>

Hi @Vladislav_Karpman  
UIKit v2.2.2 was released! Please use this version and check whether this issue is solved!

---

<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:** [December 21, 2021, 8:30am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/12 "2021-12-21T08:30:50Z")

</div>

It happens because inside method `loadInitial` in ChannelViewModel, you firstly clear cachedMessages and then waiting for response from BE.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/sendbird/original/2X/f/ffb4f734b2ebe665e61f53b78550185a7369a8ac.png)

But method `adapter.setItems` inside ChannelFragment is called before `onCacheResult` is called.  
That’s why `cachedMessages` is empty.  
You simply didn’t handle this scenario, but you should since everything happens asynchronically!

---

<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:** [December 21, 2021, 8:32am UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/13 "2021-12-21T08:32:30Z")

</div>

And I’ve recently found a new issue.  
Should I report here ?  
Or I will need to create a new topic?

---

<div class="post-metadata">

**Author:** ![Doo\_Rim](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/doo_rim/32/239_2.png) [@Doo\_Rim](https://community.sendbird.com/u/Doo_Rim)\
**Post date:** [December 21, 2021, 11:41pm UTC](https://community.sendbird.com/t/getting-crash-almost-all-the-time/3585/14 "2021-12-21T23:41:05Z")

</div>

@Vladislav_Karpman Please report a new issue to UIKit board.

> **[Sendbird Chat UIKit](https://community.sendbird.com/c/sendbird-chat-uikit/34)**
>
> Questions and answers about the Sendbird Chat UIKit!
