I have a variable in my fragment class:
private lateinit var dManager: DataManager
And I'm initializing it before the first using here:
override fun onResume() {
super.onResume()
dManager = MyApp.gManager.getDataManager(sp,level,test)
if (dManager.hp< 1) {
...
...
...
}
}
This code works ok for me and most users (99.5%), but sometimes i get crash report
lateinit property dManager has not been initialized
How can this happen? What should I do to prevent it?
MyApp.gManager.getDataManager
returnsnull
. Why can this happen? Well, that depends on how you're initializing it O_o – EpicPandaForcedManager
instead and if they can ever happen beforeonResume
. – Alexey Romanov