Android Studio Pls Check Ive been struggling to find a solution to video view being null in kotlin

This is the first time i am asking a question so sorry in advance if I’m not asking in proper format. Im relatively new to kotlin and I would love if anyone could help me. I have made an intro video and wished to display it as a videoview so I made this code but now I’m unable to solve this problem


    import android.os.Bundle

    class Intro : AppCompatActivity() {

        override fun onCreate(savedInstanceState: Bundle?) {
            val offlineUri = Uri.parse("android.resource//:$packageName/${R.raw.introa}")
            if (video_view != null) {
                video_view.setOnPreparedListener { video_view.start() }

nothing happens cause the video view is null but to make video view not null it needs to be not null which makes no sense to me and a message comes that a null cant be cast on a non null object and I’m unable to fix it please can someone suggest a solution thank you for any and all help


The reason it is null is because you haven’t assigned a View to be displayed in the Activity. You should be setting a view to the Activity first.

class Intro : AppCompatActivity(R.layout.activity_intro) as constructor
or alternatively you can use:
setContentView(R.layout.activity_intro) after super.onCreate()