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
package com.ai.sleepassistant
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_intro.*
class Intro : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val offlineUri = Uri.parse("android.resource//:$packageName/${R.raw.introa}")
if (video_view != null) {
video_view.setVideoURI(offlineUri)
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.
Use:
class Intro: AppCompatActivity(R.layout.activity_intro)
as constructor
or alternatively you can use:
setContentView(R.layout.activity_intro)
after super.onCreate()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.