In my android app with Kotlin, I have a variable "data" type of Map>,Which Product is a kotlin data class.
var data: Map<String, Array<Product>>
Product data class contains var availableQuantities. I want to loop the Map> and conserve only the product with availableQuantities != 0, and update the data variable.How can I do this? Here's my code
try {
val filteredMap: HashMap<String, Array<Product>> = HashMap()
data.forEach { (key, value) ->
val filtered = value.filter { prod -> prod.availableQuantities != 0 }
if (filtered.isNotEmpty()) {
filteredMap[key] = filtered.toTypedArray()
}
}
} catch (e: Throwable) {
e.message
}
But, after running the code an exception appear as the following image :
The following image is the description of data :
How can I correct my code to make it functionnal?
