<@U0129FYHT54> Hi, you don’t define aLiveData ```...
# announcements
p
@KayCee Hi, you don’t define aLiveData
Copy code
lateinit var aLiveData: LiveData<List<..>>
aLiveData = // define live data
val list = aLiveData.value
k
thank you, of course I did define that in my code. The point to focus is why the line "val list = aLiveData.value" can cause crash
a
If you call
aLiveData.value
before you assign
aLiveData = ...
Then it'll be null and crash
If
aLiveData
isn't guaranteed to be initialized before you use it, you should make it nullable instead
👍 1
k
aLiveData = getListFromDb()
yeah, thats right but in that case the " lateinit exception" will be presented not NPE? since there is no lateinit exception, so I think in my code the "getListFromDb()" return a null livedata? That seems unreasonable with the query:
Copy code
@Query("SELECT * FROM table")
fun getListFromDb(): LiveData<List<DataA>>
v
Put a breakpoint and see what is happening
🙏 1