I'm trying to create an Android App which uses Android Room as it's Database. I have linked two tables via their ids. If i check, whether the parent should be destroyed (because there is no child left), I come across an error with an ArrayList, that contains those child ids. I can't remove the id integer from the ArrayList of the parent.
IdList.contains(childId) returns false. Logging all integers in the IdList shows that the childId is in the IdList.
IdList.indexOf(childId) returns the right value. trying IdList.removeAt(IdList.indexOf(childId)) throws an Error tho: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
IdList.remove(childId) does nothing at all (childId can't be found).
entryModel.entry.value?.let { meal ->
val parentDao = db.mealParentDao()
val parent = parentDao.findById(meal.childParentId)
parent?.let {
if (parent.childrenIds != null &&parent.childrenIds!!.size > 1) {
var location: Int? = null
parent.childrenIds?.forEachIndexed { index, i ->
if (i == meal.childId) location = index
}
if (location != null) parent.childrenIds?.removeAt(location!!)
parent.parentType?.remove(meal.childType)
parentDao.updateMealSpecies(parent)
} else parentDao.deleteById(parent.speciesId)
}
db.mealChildDao().deleteById(meal.childId)
}
I'd expect the ArrayList without the id of the deleted child, but the ArrayList either stays the same or brings my App to a Crash.
Thanks in advance for all your help!