在游戏控制台中出现此错误 kotlin.UninitializedPropertyAccessException
Got this error in play console kotlin.UninitializedPropertyAccessException
kotlin.UninitializedPropertyAccessException:
在 com.videoplayer.VideoPlayerActivity.onStart (VideoPlayerActivity.kt:224)
在 android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1395)
在 android.app.Activity.performStart (Activity.java:7361)
在 android.app.ActivityThread.handleStartActivity (ActivityThread.java:3163)
在 android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:180)
在 android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:165)
在 android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:142)
在 android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:70)
在 android.app.ActivityThread$H.handleMessage (ActivityThread.java:1970)
定义变量
private var captionIconVisibility: Boolean = false
private var videoStarted: Boolean=false
private var lastItemPosition: Int = 1
private var itemsCount: Int = 1
private var videoWatchedTime: Long=0
private var isPreparing: Boolean=true
private lateinit var currentPlayingPlayList: List<ObjectVideo>
private lateinit var sharedPrefMemory: SharedPrefMemory
private lateinit var mCastApplication: CastApplication
private lateinit var player: SimpleExoPlayer
private var isAdPlaying: Boolean =false
private lateinit var mediaPlayer: MediaPlayer
// private lateinit var dtm: DTM
private lateinit var adPlayerManger: AdPlayerManger
private var podSize = 1
private var adType = "midroll"
private var videoPaused: Boolean = false
private lateinit var objectVideo: ObjectVideo
var currentPlayingVodPosition = 0
private var previousVideoPositionNumber=-1
private var playBackPosition:Long=0
private var numberOfVideoWatched: Int=0
private var isCaptionsOff : Boolean = false
private var isInfoLayoutVisible:Boolean = false
private lateinit var binding: ActivityVideoPlayerBinding
private lateinit var videoPlayerActivityVM: VideoPlayerActvityVM
private var midAdPositionList = ArrayList<Long>()
private var runnable: Runnable? = null
private val mHandler: Handler = Handler()
private var watchedVideoStatus: HashMap<String, Long>? = null
private lateinit var bottomSheetBehavior :BottomSheetBehavior<View>
private lateinit var bottomSheetRv: RecyclerView
private lateinit var bottomSheetPlaylistAdapter: BottomSheetPlaylistAdapter
private var bottomSheetList = ArrayList<ObjectVideo>()
private var resumedPosition:Long=0
private var pageNumber:Int =1
private var url : String = ""
private var isPreviousClicked: Boolean = false
private lateinit var mDetector: GestureDetectorCompat
private lateinit var vods:ArrayList<ObjectVideo>
companion object {
var dtm:DTM = DTM()
// var vods: ArrayList<ObjectVideo> = ArrayList()
}
我的 OnCreate 方法
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_video_player)
// flags to make media player screen full screen
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
bottomSheetBehavior = BottomSheetBehavior.from(binding.bottomsheetView.bottomSheetLayout)
bottomSheetRv = binding.bottomsheetView.bottomSheetRv
sharedPrefMemory = SharedPrefMemory(this, Context.MODE_PRIVATE, true)
// val mToolbar = binding.toolbarMediaPlayer as Toolbar
// setSupportActionBar(mToolbar)
// supportActionBar!!.setDisplayShowTitleEnabled(false)
val intentObj = intent
// dtm = intentObj.getSerializableExtra("dtm") as DTM
try {
vods = dtm.videoArrayList
bottomSheetList = vods
currentPlayingVodPosition = dtm.position
Log.d("loggingurl",vods[currentPlayingVodPosition].videoUrl);
url = dtm.url
if (!(vods.size>0 && currentPlayingVodPosition<vods.size)){
finish()
}
binding.movie = vods[currentPlayingVodPosition]
mediaPlayer = PlayerBuilder.getMediaPlayer(this, dtm, vods)
objectVideo = vods[currentPlayingVodPosition]
}
catch (e:java.lang.Exception){
Toast.makeText(this,"Something went wrong",Toast.LENGTH_SHORT).show()
}
bottomSheetBehaviorCallbacks()
binding.infoImg.setOnClickListener(this)
binding.repeatImg.setOnClickListener(this)
binding.captionImg.setOnClickListener(this)
videoPlayerActivityVM = ViewModelProviders.of(this)[VideoPlayerActvityVM::class.java]
videoPlayerActivityVM.getMoreVideosList().observe(this, androidx.lifecycle.Observer<List<ObjectVideo>> { moreVideosList ->
if (moreVideosList.isNotEmpty()) {
bottomSheetList.addAll(moreVideosList)
bottomSheetPlaylistAdapter.notifyDataSetChanged()
mediaPlayer.updatePlayList(moreVideosList)
} else {
GlobalObject.hasMoreDataMap[url] = false
}
})
mCastApplication = CastApplication(this, this)
mCastApplication.createSessionManager()
下面是我的 OnStart 方法
override fun onStart() {
super.onStart()
Log.d("LifeCycle", "OnStart is called")
if (true) {
player = mediaPlayer.getPlayer()
isCaptionsOff = sharedPrefMemory.subtitlePreference
updateCaption()
player.addListener(this)
binding.exoPlayerView.player = player
binding.exoPlayerView.setOnClickListener(this)
//var pos:Long=0
mediaPlayer.playVideo(dtm.position,videoPlayerActivityVM.getSeekTime(objectVideo,videoPaused,resumedPosition))
setBottomSheetPlayList()
videoPaused = false
}
}
此错误意味着 property
和 lateinit
在初始化之前被访问。
根据您提供的代码,我无法确定它是哪个字段,但在第 224 行检查您正在访问的 属性,因为它尚未设置。
我没有行号,所以我只是在这里猜测。
看看onCreate
:
try {
vods = dtm.videoArrayList
// ...
mediaPlayer = PlayerBuilder.getMediaPlayer(this, dtm, vods)
objectVideo = vods[currentPlayingVodPosition]
} catch (e: Exception) {
Toast.makeText(this,"Something went wrong",Toast.LENGTH_SHORT).show()
}
所以当 PlayerBuilder.getMediaPlayer(this, dtm, vods)
或之前的任何事情失败时
mediaPlayer
保持未初始化状态,
- 用户祝酒,但作为开发人员的您没有收到异常报告,
player = mediaPlayer.getPlayer()
在 onStart
期间发生,这会导致崩溃,因为 (1).
我没有适合您的修复程序,代码庞大,难以阅读且难以推理。祝你好运。
定义变量
private var captionIconVisibility: Boolean = false
private var videoStarted: Boolean=false
private var lastItemPosition: Int = 1
private var itemsCount: Int = 1
private var videoWatchedTime: Long=0
private var isPreparing: Boolean=true
private lateinit var currentPlayingPlayList: List<ObjectVideo>
private lateinit var sharedPrefMemory: SharedPrefMemory
private lateinit var mCastApplication: CastApplication
private lateinit var player: SimpleExoPlayer
private var isAdPlaying: Boolean =false
private lateinit var mediaPlayer: MediaPlayer
// private lateinit var dtm: DTM
private lateinit var adPlayerManger: AdPlayerManger
private var podSize = 1
private var adType = "midroll"
private var videoPaused: Boolean = false
private lateinit var objectVideo: ObjectVideo
var currentPlayingVodPosition = 0
private var previousVideoPositionNumber=-1
private var playBackPosition:Long=0
private var numberOfVideoWatched: Int=0
private var isCaptionsOff : Boolean = false
private var isInfoLayoutVisible:Boolean = false
private lateinit var binding: ActivityVideoPlayerBinding
private lateinit var videoPlayerActivityVM: VideoPlayerActvityVM
private var midAdPositionList = ArrayList<Long>()
private var runnable: Runnable? = null
private val mHandler: Handler = Handler()
private var watchedVideoStatus: HashMap<String, Long>? = null
private lateinit var bottomSheetBehavior :BottomSheetBehavior<View>
private lateinit var bottomSheetRv: RecyclerView
private lateinit var bottomSheetPlaylistAdapter: BottomSheetPlaylistAdapter
private var bottomSheetList = ArrayList<ObjectVideo>()
private var resumedPosition:Long=0
private var pageNumber:Int =1
private var url : String = ""
private var isPreviousClicked: Boolean = false
private lateinit var mDetector: GestureDetectorCompat
private lateinit var vods:ArrayList<ObjectVideo>
companion object {
var dtm:DTM = DTM()
// var vods: ArrayList<ObjectVideo> = ArrayList()
}
我的 OnCreate 方法
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_video_player)
// flags to make media player screen full screen
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
bottomSheetBehavior = BottomSheetBehavior.from(binding.bottomsheetView.bottomSheetLayout)
bottomSheetRv = binding.bottomsheetView.bottomSheetRv
sharedPrefMemory = SharedPrefMemory(this, Context.MODE_PRIVATE, true)
// val mToolbar = binding.toolbarMediaPlayer as Toolbar
// setSupportActionBar(mToolbar)
// supportActionBar!!.setDisplayShowTitleEnabled(false)
val intentObj = intent
// dtm = intentObj.getSerializableExtra("dtm") as DTM
try {
vods = dtm.videoArrayList
bottomSheetList = vods
currentPlayingVodPosition = dtm.position
Log.d("loggingurl",vods[currentPlayingVodPosition].videoUrl);
url = dtm.url
if (!(vods.size>0 && currentPlayingVodPosition<vods.size)){
finish()
}
binding.movie = vods[currentPlayingVodPosition]
mediaPlayer = PlayerBuilder.getMediaPlayer(this, dtm, vods)
objectVideo = vods[currentPlayingVodPosition]
}
catch (e:java.lang.Exception){
Toast.makeText(this,"Something went wrong",Toast.LENGTH_SHORT).show()
}
bottomSheetBehaviorCallbacks()
binding.infoImg.setOnClickListener(this)
binding.repeatImg.setOnClickListener(this)
binding.captionImg.setOnClickListener(this)
videoPlayerActivityVM = ViewModelProviders.of(this)[VideoPlayerActvityVM::class.java]
videoPlayerActivityVM.getMoreVideosList().observe(this, androidx.lifecycle.Observer<List<ObjectVideo>> { moreVideosList ->
if (moreVideosList.isNotEmpty()) {
bottomSheetList.addAll(moreVideosList)
bottomSheetPlaylistAdapter.notifyDataSetChanged()
mediaPlayer.updatePlayList(moreVideosList)
} else {
GlobalObject.hasMoreDataMap[url] = false
}
})
mCastApplication = CastApplication(this, this)
mCastApplication.createSessionManager()
下面是我的 OnStart 方法
override fun onStart() {
super.onStart()
Log.d("LifeCycle", "OnStart is called")
if (true) {
player = mediaPlayer.getPlayer()
isCaptionsOff = sharedPrefMemory.subtitlePreference
updateCaption()
player.addListener(this)
binding.exoPlayerView.player = player
binding.exoPlayerView.setOnClickListener(this)
//var pos:Long=0
mediaPlayer.playVideo(dtm.position,videoPlayerActivityVM.getSeekTime(objectVideo,videoPaused,resumedPosition))
setBottomSheetPlayList()
videoPaused = false
}
}
此错误意味着 property
和 lateinit
在初始化之前被访问。
根据您提供的代码,我无法确定它是哪个字段,但在第 224 行检查您正在访问的 属性,因为它尚未设置。
我没有行号,所以我只是在这里猜测。
看看onCreate
:
try {
vods = dtm.videoArrayList
// ...
mediaPlayer = PlayerBuilder.getMediaPlayer(this, dtm, vods)
objectVideo = vods[currentPlayingVodPosition]
} catch (e: Exception) {
Toast.makeText(this,"Something went wrong",Toast.LENGTH_SHORT).show()
}
所以当 PlayerBuilder.getMediaPlayer(this, dtm, vods)
或之前的任何事情失败时
mediaPlayer
保持未初始化状态,- 用户祝酒,但作为开发人员的您没有收到异常报告,
player = mediaPlayer.getPlayer()
在onStart
期间发生,这会导致崩溃,因为 (1).
我没有适合您的修复程序,代码庞大,难以阅读且难以推理。祝你好运。