Android Studio 3.2
kotlin_version 1.2.41
I am getting a UnsupportedOperationException mutablelist addAll.
I am passing a MutableList so not sure why I would get this runtime time exeception.
When I print the names of the classes I get the following collection classes
I/System.out: class java.util.ArrayList
I/System.out: class java.util.Collections$EmptyList
This is the mapper method that return a MutableList
override fun map(cursor: Cursor): MutableList<InsectDataModel> {
val insectDataModelList: MutableList<InsectDataModel> = mutableListOf()
cursor.moveToFirst()
while(cursor.moveToNext()) {
InsectDataModel().let {
it.friendlyName = cursor.getString(cursor.getColumnIndexOrThrow(InsectContract.COLUMN_FRIENDLY_NAME))
it.scientificName = cursor.getString(cursor.getColumnIndexOrThrow(InsectContract.COLUMN_SCIENTIFIC_NAME))
it.dangerLevel = cursor.getInt(cursor.getColumnIndexOrThrow(InsectContract.COLUMN_DANGER_LEVEL))
insectDataModelList.add(it)
}
}
cursor.close()
return insectDataModelList
}
Adapter class that will load the list using addAll
class InsectAdapter(private var insectList: MutableList<InsectDataModel>): RecyclerView.Adapter<InsectAdapter.CustomInsectHolder>() {
fun loadInsects(insectList: MutableList<InsectDataModel>) {
println(insectList.javaClass)
println(this.insectList.javaClass)
this.insectList.addAll(insectList) /* Unsupported Exception here */
notifyDataSetChanged()
}
}
Calling insectAdapter
public void loadAllInsects(final Cursor cursor) {
insectInteractorMapper = new InsectInteractorMapperImp();
insectAdapter.loadInsects(insectInteractorMapper.map(cursor));
}