无法销毁活动...无法调用观察者方法

时间:2019-05-18 16:33:57

标签: android

应用程序崩溃,如果我尝试导航到其他活动并关闭当前活动,则会收到以下错误:

  

无法破坏活动{com.example.ui.login.LoginActivity}:   java.lang.RuntimeException:无法调用观察者方法

view.findNavController().navigate(R.id.action_loginFragment_to_mainActivity)

activity!!.finish()

此代码在一个片段内被调用。注释掉活动!!完成可防止崩溃。这是完整的错误日志:

2019-05-18 18:29:01.561 15025-15025/com.example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example, PID: 15025
    java.lang.RuntimeException: Unable to destroy activity {com.example.ui.login.LoginActivity}: java.lang.RuntimeException: Failed to call observer method
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4383)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4401)
        at android.app.ActivityThread.-wrap5(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
     Caused by: java.lang.RuntimeException: Failed to call observer method
        at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:225)
        at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:193)
        at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:184)
        at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:36)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:355)
        at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:309)
        at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:328)
        at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:138)
        at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:124)
        at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:122)
        at androidx.lifecycle.ReportFragment.onDestroy(ReportFragment.java:107)
        at android.app.Fragment.performDestroy(Fragment.java:2768)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1432)
        at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1557)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1618)
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3027)
        at android.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3007)
        at android.app.FragmentController.dispatchDestroy(FragmentController.java:244)
        at android.app.Activity.performDestroy(Activity.java:7217)
        at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1249)
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4370)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4401) 
        at android.app.ActivityThread.-wrap5(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
     Caused by: kotlin.UninitializedPropertyAccessException: lateinit property initialState has not been initialized
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.access$getInitialState$p(CircularProgressButton.kt:21)
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton$morphAnimator$2.invoke(CircularProgressButton.kt:68)
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton$morphAnimator$2.invoke(CircularProgressButton.kt:21)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.getMorphAnimator(Unknown Source:7)
        at br.com.simplepass.loadingbutton.customViews.CircularProgressButton.dispose(CircularProgressButton.kt:168)
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.lifecycle.ClassesInfoCache$MethodReference.invokeCallback(ClassesInfoCache.java:215)
        at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeMethodsForEvent(ClassesInfoCache.java:193) 
        at androidx.lifecycle.ClassesInfoCache$CallbackInfo.invokeCallbacks(ClassesInfoCache.java:184) 
        at androidx.lifecycle.ReflectiveGenericLifecycleObserver.onStateChanged(ReflectiveGenericLifecycleObserver.java:36) 
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:355) 
        at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:309) 
        at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:328) 
        at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:138) 
        at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:124) 
        at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:122) 
        at androidx.lifecycle.ReportFragment.onDestroy(ReportFragment.java:107) 
        at android.app.Fragment.performDestroy(Fragment.java:2768) 
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1432) 
        at android.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1557) 
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1618) 
        at android.app.FragmentManagerImpl.dispatchMoveToState(FragmentManager.java:3027) 
        at android.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3007) 
        at android.app.FragmentController.dispatchDestroy(FragmentController.java:244) 
        at android.app.Activity.performDestroy(Activity.java:7217) 
        at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1249) 
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4370) 
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4401) 
        at android.app.ActivityThread.-wrap5(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6494) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

1 个答案:

答案 0 :(得分:0)

它是由lateinit属性initialState没有被初始化引起的。 请用 circleprogressbutton.saveInitialState()