John Aoussou
11/12/2021, 11:38 AMval items = viewModel.readAllData.observeAsState()
val TAG = "check"
val item1 = items.value?.get(0)?.original
Log.i(TAG,item1.toString())
However, if I try to show the text in a Text element like so
Column{
Text(text = item1!!)
}
it tells me the List is empty ¯\_(ツ)_/¯Csaba Kozák
11/12/2021, 12:55 PM!! you have an unsafe operator here. You should check if it is not null (and empty), and display it in that case.
val items by viewModel.readAllData.observeAsState()
if (!items.isNullOrEmpty()) {
Text(text = items!!.first()) // safe to call here
}John Aoussou
11/12/2021, 1:14 PMCsaba Kozák
11/12/2021, 1:29 PM?. , so event when it is null first, you should see itt logging null, but no crash.Csaba Kozák
11/12/2021, 1:33 PMif, you could also use items?.let { if you want.