0
votes

I have an adapter class and in which I initialise a map as follows:

internal class MyAdapter(private var itemList: List<Items>) :
        RecyclerView.Adapter<MyAdapter.MyViewHolder>() {

    private var itemStates: MutableMap<Int, ArrayList<Boolean>> = mutableMapOf()

    init {
        itemList.forEachIndexed { index, itemObject->

            val capacity  = if(itemObject.getItemTYPE() == Item.ITEM_TYPE.FOOD) 3 else 5

            itemStates[index] = ArrayList(initialCapacity = capacity) //error is shown here
        }
    }

Everything else seems fine, but when I run this, I get the following error:

None of the following functions can be called with the arguments supplied:

public final fun (): kotlin.collections.ArrayList /* = java.util.ArrayList */ defined in kotlin.collections.ArrayList

public final fun (p0: (MutableCollection<out Boolean!>..Collection<Boolean!>?)): kotlin.collections.ArrayList /* = java.util.ArrayList */ defined in kotlin.collections.ArrayList

public final fun (p0: Int): kotlin.collections.ArrayList /* = java.util.ArrayList */ defined in kotlin.collections.ArrayList

Any help or suggestion will be highly appreciated.

1
Please update your question to show the full error message.Thomas
@Thomas I have updated itXavierCodster
you have to put some constant value here. it will not use dynamic initialiseYogendra

1 Answers

0
votes

As you can see in the error message, the parameter is named p0 and not initialCapacity. This is probably happening because ArrayList is imported straight from Java (see the = java.util.ArrayList part), and in Java, parameter names aren't part of the function signature. Probably the JAR that your compiler is referencing has had the names optimized away. See also this question.

Rather than writing ArrayList(p0 = capacity), I would just write ArrayList(capacity) so you don't depend on the argument name anymore.