Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: TextView must not be null (Android/Kotlin)

Tags:

I have the following ViewHolder class for my Recycler View,

inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        private val dateText = itemView.itemDateSummaryList
        private val systolicVal = itemView.systolicValue
        private val diastolicVal = itemView.diastolicValue

        fun update(listItem: SummaryListItemModel) {
            Log.i(TAG, "Update method called " + listItem.date)
            dateText.text = listItem.date
            systolicVal.text = listItem.sysVal.toInt().toString()
            diastolicVal.text = listItem.diasVal.toInt().toString()
        }

    }

But when I run the app an error comes up at the dateText.text = listItem.date saying,

java.lang.IllegalStateException: dateText must not be null
at *****.******.*****.ui.detailview.bloodpressure.SummaryListAdapter$ItemViewHolder.update(SummaryListAdapter.kt:68)

But the listItem.date is not null I have check with the Log.

like image 497
kokilayaa Avatar asked Nov 21 '17 06:11

kokilayaa


1 Answers

the error is not about listItem.date, the error says that the dateText textview to which you are trying to set text is null ,

double check you are using the correct textview

Possibilities :
1) you might be using wrong id of textview
2) you may have used wrong file while inflating view.

ctrl + click on itemDateSummaryList and see whether the textview is from he same layout file you have infate or otherwise

like image 123
Irony Stack Avatar answered Oct 05 '22 05:10

Irony Stack