美文网首页
onDestroy报空指针boolean androidx.fr

onDestroy报空指针boolean androidx.fr

作者: Moosen | 来源:发表于2020-06-08 12:38 被阅读0次
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err: java.lang.RuntimeException: Unable to destroy activity {com.leite.app.dayitem/com.leite.app.dayitem.view.user.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4167)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4185)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread.-wrap6(ActivityThread.java)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1521)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.os.Looper.loop(Looper.java:154)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6077)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.Fragment.performDetach(Fragment.java:2849)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1034)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2659)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentManagerImpl.dispatchDestroy(FragmentManagerImpl.java:2644)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentController.dispatchDestroy(FragmentController.java:329)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.fragment.app.FragmentActivity.onDestroy(FragmentActivity.java:366)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at androidx.appcompat.app.AppCompatActivity.onDestroy(AppCompatActivity.java:233)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at com.leite.app.dayitem.base.BaseActivity.onDestroy(BaseActivity.java:209)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.Activity.performDestroy(Activity.java:6864)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1153)
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4154)
    
    java.lang.RuntimeException: Unable to destroy activity {com.leite.app.dayitem/com.leite.app.dayitem.view.user.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androidx.fragment.app.FragmentManagerImpl.isDestroyed()' on a null object reference
    2020-06-08 12:33:57.459 8909-8909/com.leite.app.dayitem W/System.err:     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4167)
    

    是因为自己在Fragment重点onDetach增加了如下代码,自己把它设为了空值导致的,新版本的Fragment不会再产生这个问题,可以直接把这部分代码去掉。

      @Override
        public void onDetach() {//避免api bug :IllegalStateException No activity
            super.onDetach();
            LogUtils.d(TAG, "onDetach");
            try {
                Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
                childFragmentManager.setAccessible(true);
                childFragmentManager.set(this, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

    相关文章

      网友评论

          本文标题:onDestroy报空指针boolean androidx.fr

          本文链接:https://www.haomeiwen.com/subject/kvmltktx.html