我是一名新开发人员(如果我可以称自己为一个)正在制作警报应用程序。我想我制作了应用程序的其他部分,但无论我多么努力,我都不知道如何修复错误。要访问AlarmManager.kt中的实例,我不禁要创建实例伴随对象。但我想这会导致问题......请有人告诉我如何解决这个错误吗?提前致谢!
kotlin.UninitializedPropertyAccessException:lateinit 属性实例尚未初始化
↓ SampleApplication.kt
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
instance = this
}
companion object {
lateinit var instance: SampleApplication private set
}
}
↓AlarmManager.kt
object AlarmManager {
var mService: MusicService? = null
lateinit var mediaPlayer: MediaPlayer
lateinit var mView: View
lateinit var mTimer: Timer
val tag1 = "alarm1"
val tag2 = "alarm2"
private val windowManager: WindowManager by lazy {
SampleApplication.instance.getSystemService(Context.WINDOW_SERVICE) as WindowManager
}