本文介绍了ActivityThread.java空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在生产中的少数设备中遇到了一个奇怪的异常,我不确定导致崩溃的原因.我将堆栈跟踪信息与FABRIC/Crashlytics上的崩溃屏幕快照一起附加

I am getting a strange exception in few of my devices on production and I am not sure about the cause of this crash. I am attaching my stack trace with screenshots of the crash on 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)

这是我的onDestoryActivity方法

Here is my 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);
    }

任何人都可以看看是否也发生了同样的事情,并帮助我调试问题.

Can anyone please have a look if the same has happened to you too and help me debug the issue.

推荐答案

在调用其他方法之前,请勿调用super.onDestroy():

You should not call super.onDestroy() before calling another method like this:

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

应该是这样的:

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

这是因为调用super.onDestroy()后您的活动可能已经完成.有关更多详细信息,请查看 onDestroy() 代码.

It is because your activity could be already finished after you're calling super.onDestroy(). For more details, please take a look at onDestroy() code.

这篇关于ActivityThread.java空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:54