Reputation: 414
I have a MutableLiveData
and I want to add a List
inside, but seems the below code doesn't work:
private var factsLive: MutableLiveData<List<Fact>>? = null
private fun getObserver(): SingleObserver<List<Fact>> {
return object : SingleObserver<List<Fact>> {
override fun onSuccess(t: List<Fact>) {
Log.d("test", "Succes")
factsLive?.value = t
}
override fun onSubscribe(d: Disposable) {
Log.d("test", "Subscribe")
}
override fun onError(e: Throwable) {
Log.d("test", "Error")
}
}
}
This returns me MutableLiveData
like null.
Upvotes: 0
Views: 1631
Reputation: 921
Make your variable like this:
private var factsLive: MutableLiveData<List<Fact>> = MutableLiveData<>()
Upvotes: 1