kotlin findViewById returns null
I have the following code which after clicking on the button findViewById returns null but when I set the onclick attribute of the picture itself to change the picture there is no null exception returned.
This code returns null exception:
private lateinit var imageView1: ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
fun change(view: View){
try {
imageView1 =...