ActivityThread.java空指针异常

时间:2018-04-20 03:54:35

标签: android android-activity

我在生产中的一些设备中遇到一个奇怪的例外,我不确定这次崩溃的原因。我在FABRIC / Crashlytics

上附上我的堆栈跟踪以及崩溃的屏幕截图
Fatal Exception: java.lang.RuntimeException
Unable to destroy activity {com.zotopay.zoto/com.zotopay.zoto.activityviews.DashboardActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map$Entry.getValue()' on a null object reference
android.app.ActivityThread.performDestroyActivity (ActivityThread.java:3969)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:754)
Caused by java.lang.NullPointerException
Attempt to invoke interface method 'java.lang.Object java.util.Map$Entry.getValue()' on a null object reference
android.arch.lifecycle.LifecycleRegistry.isSynced (LifecycleRegistry.java:145)
android.app.Instrumentation.callActivityOnDestroy (Instrumentation.java:1148)
android.app.ActivityThread.performDestroyActivity (ActivityThread.java:3956)
android.app.ActivityThread.handleDestroyActivity (ActivityThread.java:3987)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:754)

这是我的onDestoryMethod of Activity

@Override
    protected void onDestroy() {
        super.onDestroy();
        clearHandlerCallbacks(activityDataHandler);
        clearHandlerCallbacks(statusColorHandler);
    }

public void clearHandlerCallbacks(Handler handler) {
        if (Common.nonNull(handler))
            handler.removeCallbacksAndMessages(null);
    }

任何人都可以看看你是否也遇到过这种情况并帮助我调试问题。

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

在调用另一种方法之前,不应该调用super.onDestroy()

@Override
protected void onDestroy() {
  super.onDestroy();
  clearHandlerCallbacks(activityDataHandler);
  clearHandlerCallbacks(statusColorHandler);
}

它应该是这样的:

@Override
protected void onDestroy() {
  clearHandlerCallbacks(activityDataHandler);
  clearHandlerCallbacks(statusColorHandler);
  super.onDestroy();
}

这是因为在您致电super.onDestroy()后,您的活动可能已经完成。有关详细信息,请查看here代码。