I'm using ObjectBox and I'm trying to save data with ToMany but I get this error:
kotlin.UninitializedPropertyAccessException: lateinit property fotos has not been initialized
- ObjectBox Version: 2.2.0
- Android SDK Version: 28
- Kotlin Version: 1.2.71
Here are my classes:
@Entity
data class Ficha (
@Id var id: Long = 0,
var nombre: String,
var alias: String,
var fecha: Date? = null
) {
@Backlink (to = "ficha")
lateinit var fotos: ToMany<Foto>
}
@Entity
data class Foto (
@Id
var id: Long = 0,
var tipo: Int = 0,
var ruta: String = "",
var fecha: Date? = null
) {
lateinit var ficha: ToOne<Ficha>
}
And I'm trying to save this:
val ficha = Ficha(id = 0, nombre = nombre, alias = alias, fecha = Date()).apply {
val foto1 = Foto(id = 0, tipo = 1, ruta = "C://Pepe//Cantu//1", fecha = Date())
val foto2 = Foto(id = 0, tipo = 2, ruta = "C://Pepe//Cantu//2", fecha = Date())
val foto3 = Foto(id = 0, tipo = 3, ruta = "C://Pepe//Cantu//3", fecha = Date())
this.fotos.add(foto1)
this.fotos.add(foto2)
this.fotos.add(foto3)
}
fichaDB.put(ficha)
How to fix it?