Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalArgumentException on parameter convertView at Adapter.getView Kotlin android

java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter convertView
Adapter.getView
 at android.widget.AbsListView.obtainView(AbsListView.java:2346)
        at android.widget.ListView.makeAndAddView(ListView.java:1876)
        at android.widget.ListView.fillDown(ListView.java:702)
        at android.widget.ListView.fillFromTop(ListView.java:763)
        at android.widget.ListView.layoutChildren(ListView.java:1671)
        at android.widget.AbsListView.onLayout(AbsListView.java:2148)

This is logcat of android. I tried with java it's working fine base adapter something wrong in Adapter or other. I tried with the public constructor and also array list count 3 found i checked it. Alway it's crash at getView

MyAdapter Code::

   inner class MyAppAdapter constructor(private val parkingList: ArrayList<App>, private val mContext: Context) : BaseAdapter() {

        override fun getCount(): Int {
            return this.parkingList.size
        }

        override fun getItem(position: Int): Any {
            return position
        }

        override fun getItemId(position: Int): Long {
            return position.toLong()
        }

        override fun getView(position: Int, convertView: View, parent: ViewGroup): View? {
            val viewHolder: ViewHolder
            var rowView: View? = convertView
            if (rowView == null) {
                rowView = LayoutInflater.from(mContext).inflate(R.layout.item_more_apps, parent, false)
                viewHolder = ViewHolder()
                viewHolder.appIcon = rowView.findViewById(R.id.appIcon)
                viewHolder.appName = rowView.findViewById(R.id.appName)
                viewHolder.appDescription = rowView.findViewById(R.id.appDescription)
                rowView.tag = viewHolder
            } else {
                viewHolder = convertView.tag as ViewHolder
            }
            viewHolder.appName!!.text = String.format("%s", this.parkingList[position].name)
            viewHolder.appDescription!!.text = String.format("%s", this.parkingList[position].description)
            Glide.with(applicationContext).load(this.parkingList[position].icon).into(viewHolder.appIcon!!)
            rowView?.setOnClickListener {
                try {
                    startActivity(Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + [email protected][position].link)))
                } catch (e: ActivityNotFoundException) {
                    startActivity(Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + [email protected][position].link)))
                }
            }
            return rowView
        }

        inner class ViewHolder {
            var appDescription: TextView? = null
            var appIcon: ImageView? = null
            var appName: TextView? = null
        }
    }

Used at AsyncTask -> onPostExecute

  myAppAdapter = MyAppAdapter(appArrayList, applicationContext)
            lvPoses!!.adapter = myAppAdapter

Variable Decleared like this

   lateinit var myAppAdapter: MyAppAdapter
    private val appArrayList = ArrayList<App>()
    private var lvPoses: ListView? = null
like image 292
Jigar Patel Avatar asked Dec 10 '22 06:12

Jigar Patel


1 Answers

convertView can be null if no view has been created yet. Fix parametr declaration:

override fun getView(position: Int, convertView: View?, parent: 
     ViewGroup): View? {
...
}
like image 180
egoldx Avatar answered Feb 13 '23 04:02

egoldx