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)
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
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?
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!