我已經擴展ArrayAdapter的微調:參數爲空在ArrayAdaper
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
}
}
我得到異常:
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)
任何想法如何解決呢?
異常很清楚。您正在爲convertView參數傳遞null。 – Arno
此方法由Android框架調用,參數實際上定義爲可爲空,因此應允許空值。 –
@Dawid你確定你的代碼和你在這裏發佈的代碼是一樣的嗎?具體來說,'convertView'參數是否真的被聲明爲可空? –