I'm really new to programming in Android. I have the following error when I try to show a list after the update, delete or modify.
This is the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.isc.dog, PID: 12520
java.lang.NullPointerException: Parameter specified as non-null
is null: method
kotlin.jvm.internal.Intrinsics.checkNotNullParameter,
parameter it
I know it could be related to this piece of code below.
fun getDoges() : MutableLiveData<List<Dog>> {
val listaFinal = MutableLiveData<List<Dog>>()
firestore
.collection("dogesApp")
.document(codigoUsuario)
.collection("misDoges")
.addSnapshotListener { instantanea, e -> //Le toma una foto/recupera los lugares del usuario
if (e != null) {
Log.d("Firestore","Error recuperando Mascotas", e)
return@addSnapshotListener
}
if (instantanea !=null) { //Hay datos en la recuperación
val lista = ArrayList<Dog>()
val doges= instantanea.documents
doges.forEach {
val dog = it.toObject(Dog::class.java)
if (dog != null) { //Si se pudo convertir a un lugar
lista.add(dog)
}
}
listaFinal.value = lista
}
}
return listaFinal
}
I don't know how to fix this exception.