Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView

后端 未结 4 696
刺人心
刺人心 2021-01-03 21:54

I got this error just after converted the adapter code to Kotlin:

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.         


        
4条回答
  •  有刺的猬
    2021-01-03 22:31

    All correct solutions are already posted above. Just one more with some code and ViewBinding:

    class SpinnerAdapter(
          context: Context,
          private val items: List
    ) : BaseAdapter() {
    
    private var layoutInflater: LayoutInflater = LayoutInflater.from(context)
    
    override fun getView(i: Int, convertView: View?, viewGroup: ViewGroup): View {
        return if (convertView != null) {
            convertView
        } else {
            val view = layoutInflater.inflate(R.layout.item_spinner, null)
            val binding = ItemSpinnerBinding.bind(view)
            val item = items[i]
            binding.name.text = item.name
            view
        }
    }
    
    //more overridde methods
    }
    

    Where my R.layout.item_spinner has a TextView with an Id called "name".

提交回复
热议问题