Getting crash almost all the time

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:

 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)
3 Likes

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

I use this dependency:
implementation ‘com.sendbird.sdk:uikit:2.2.1’

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

Do you use Chat SDK? only UIKit SDK?

  • Did you customize ChannelFragment?

I use UIKit SDK and yes I customized a bit ChannelFragment

How did you customize it?

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)
                }

I am trying to reproduce your issue. I cannot reproduce it…! :frowning:
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?

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

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

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!

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

@Vladislav_Karpman Please report a new issue to UIKit board.