Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7188

UnsupportedOperationException when adding to a map in kotlin

$
0
0

I have a crash, that only happened once in my app, due to an UnsupportedOperationException when I try to add an item to a map. For the stacktrace it seems that an AbstractMap is instantiated instead of a MutableMap. The code is in kotlin:

val productMap: MutableMap<ProductModel, Int> =            binding.myView.getProductMap() as? MutableMap<ProductModel, Int>                ?: mutableMapOf()            presenter.getProduct()?.let {                productMap.put(it, 0)            }

Could it be that kotlin/java did something weird behind curtains or is there anything I am missing?

The stacktrace:

Fatal Exception: java.lang.UnsupportedOperationException       at java.util.AbstractMap.put(AbstractMap.java:218)       at com.package.MyView.method2(MyView.java:108)       at com.package.MyParentView.method1(MyParentView.java:1278)

Viewing all articles
Browse latest Browse all 7188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>