KayCee
12/14/2020, 4:44 AMlateinit var aLiveData: LiveData<List<..>>
val list = aLiveData.value
The crashlytics said there is a NPE in the second line. It occurs occasionally. I dont really get why, I thought it could be about the lateinit so I change it to a nullable variable (despite the fact there is no "lateinit exception"). Is that correct?Animesh Sahu
12/14/2020, 7:46 AMval list get() = aLiveData.value
Animesh Sahu
12/14/2020, 7:47 AMKayCee
12/14/2020, 7:52 AMval list = someLiveData.value
directly?Animesh Sahu
12/14/2020, 7:52 AMsomeLiveData.value
which doesn't exist at the time of creating variable list
Animesh Sahu
12/14/2020, 7:53 AMval list get() = aLiveData.value
is basically like a function and doesn't have any field in it, you can think of it as fun getList(): List<...> = someLiveData.value
KayCee
12/14/2020, 8:02 AMval list: <DataTye>
get () =...
so backing properties in kotlin is something like you create a not null list and initialize it to a value?KayCee
12/14/2020, 8:03 AMvar aLiveData: LiveData<List<T>>? = null
then
val list = aLiveData?.value
shoud be no prob now?Animesh Sahu
12/14/2020, 8:04 AMAnimesh Sahu
12/14/2020, 8:04 AMAnimesh Sahu
12/14/2020, 8:05 AMKayCee
12/14/2020, 8:11 AMvar aLiveData: LiveData<List<T>>? = null
aLiveData = getDataFromDb()
val list = aLiveData?.value
Animesh Sahu
12/14/2020, 8:12 AMAnimesh Sahu
12/14/2020, 8:13 AMKayCee
12/14/2020, 8:19 AMAnimesh Sahu
12/14/2020, 8:19 AM