<Why I get null when I try to access view by ID?> ...
# stackoverflow
u
Why I get null when I try to access view by ID? I have a function, cauntMe() that is triggered when the button is clicked. fun cauntMe(view: View){ val textView = view.findViewById(R.id.textView) val countString = textView.text.toString() var count: Int = Integer.parseInt(countString) count++ textView.text = count.toString() } Here is XML declaration of the view: In triggered function this row return null: view.findViewById(R.id.textView) Here is class: class MainActivity : AppCompatActivity() { override fun...