class MyApp : Application() {
init {
instance = this
}
...
companion object {
lateinit var instance: MyApp
private set
}
}
< /code>
... что должно быть инициализировано до того, как будут запущены любые другие компоненты приложения (действия, услуги и т. Д.). И для 99,99% наших пользователей все работает правильно.Exception java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:4051)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4325)
at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2574)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8757)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
Caused by kotlin.UninitializedPropertyAccessException: lateinit property instance has not been initialized
at mypackage.MyApp$Companion.getInstance (MyApp.kt:312)
at mypackage.MyActivity. (MyActivity.kt:72)
at java.lang.Class.newInstance
at android.app.AppComponentFactory.instantiateActivity (AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity (CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity (Instrumentation.java:1328)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:4038)
Примечание в трассировке стека MyActivity пытается получить доступ к myApp.instance , но, очевидно, это не было инициализировано! Это будет означать, что деятельность будет запущена до того, как класс приложений был создан (?)
Что может происходить?
Мы используем объект приложения подклассов, например: < /p> [code]class MyApp : Application() { init { instance = this }
...
companion object { lateinit var instance: MyApp private set } } < /code> ... что должно быть инициализировано до того, как будут запущены любые другие компоненты приложения (действия, услуги и т. Д.). И для 99,99% наших пользователей все работает правильно.Exception java.lang.RuntimeException: at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:4051) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2574) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:226) at android.os.Looper.loop (Looper.java:313) at android.app.ActivityThread.main (ActivityThread.java:8757) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067) Caused by kotlin.UninitializedPropertyAccessException: lateinit property instance has not been initialized at mypackage.MyApp$Companion.getInstance (MyApp.kt:312) at mypackage.MyActivity. (MyActivity.kt:72) at java.lang.Class.newInstance at android.app.AppComponentFactory.instantiateActivity (AppComponentFactory.java:95) at androidx.core.app.CoreComponentFactory.instantiateActivity (CoreComponentFactory.java:45) at android.app.Instrumentation.newActivity (Instrumentation.java:1328) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:4038) [/code] Примечание в трассировке стека MyActivity пытается получить доступ к myApp.instance , но, очевидно, это не было инициализировано! Это будет означать, что деятельность будет запущена до того, как класс приложений был создан (?) Что может происходить?