Hello guys :slightly_smiling_face: I hope someone ...
# rx
m
Hello guys 🙂 I hope someone can give me a hint .. I’m working on a simple weather app .. Once I get data from the API I want to store it using Realm and call a method to fetch data from the database. But the problem is that the method for fetching from db is called before the data are saved into Realm, so I get this : E/LandingViewModel: onError with java.util.NoSuchElementException List is empty.
g
Hey! Looks like your stream returns a maybe, which inherently can or cannot have any element. The stream didnt emit anything, thats why you get this exception.
g
Please, do not crosspost your messages
Stream returns Flowable, not Maybe
Obviously you get empty list as result, it’s completely valid situation, so you have 2 ways: 1. check that list is not empty before using
first()
, otherwise you get NoSuchElementException (what you have now) 2. Filter empty lists:
.filter { it.isNotEmpty() }