Why is it not recognized in main activity when I create text view?

enter image description hereI created a TextView inside activity_main.xml and specified an ID for it, but when I go into MainActivity and click on that ID, it does not recognize TextView, and what does the red line under everything look like? How should I solve this problem?

enter image description here

enter image description here

Answer

The mainActivity does not know where the txt_test is coming from so you have to give it the reference. I would recommend either use ViewBinding or use the old:

val txt = findViewById(R.id.the_id_of_your_textView)

Leave a Reply

Your email address will not be published. Required fields are marked *