Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter specified as non-null is null in ArrayAdaper

Tags:

android

kotlin

I've extended ArrayAdapter for spinner:

class OrderAdapter(context: Context, resource: Int, objects: List<Order>) : ArrayAdapter<Order>(context, resource, objects) {
        override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
            val view = super.getView(position, convertView, parent)
            view?.let { view.find<TextView>(android.R.id.text1).text = getItem(position).name }
            return view
        }
        override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View? {
            val view = super.getDropDownView(position, convertView, parent)
            view?.let {view.find<TextView>(android.R.id.text1).text = getItem(position).name }
            return view
        }
    }

I'm getting exception:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
                                                                                          at com.github.blabla.endlesss.ui.adapter.OrderAdapter.getView(OrderAdapter.kt:0)

Any ideas how to fix it?

like image 497
Dawid Hyży Avatar asked Feb 25 '16 08:02

Dawid Hyży


2 Answers

This issue was caused by incremental compile. Just needed to rebuild project after converting from Java.

like image 50
Dawid Hyży Avatar answered Oct 23 '22 05:10

Dawid Hyży


Please check the sample below:

override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View? {
    return getCustomView(position, convertView, parent)
}

override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
    return getCustomView(position, convertView, parent)
}

fun getCustomView(position: Int, convertView: View?, parent: ViewGroup): View? {
    val rootView: View? = LayoutInflater.from(context).inflate(R.layout.my_custom_view, parent, false)
    return rootView
}

The returned value should be nullable.

like image 38
Denys Makhov Avatar answered Oct 23 '22 05:10

Denys Makhov