我一直在获取setnextanim崩溃,但没有在我的代码中找到确切的位置。这是我唯一使用Nextanim的地方:

@Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        Animation defaultAnimation = super.onCreateAnimation(transit, enter, nextAnim);

        if (defaultAnimation == null && nextAnim != 0) {
            defaultAnimation = AnimationUtils.loadAnimation(getActivity(), nextAnim);
        }

        if (defaultAnimation != null) {
            if (getView() != null) {
                getView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }

            defaultAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                public void onAnimationEnd(Animation animation) {
                    if (getView() != null) {
                        getView().setLayerType(View.LAYER_TYPE_NONE, null);
                    }
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });
        }

        return defaultAnimation;
    }

这是我能找到的线索:
FATAL EXCEPTION: main
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.app.Fragment.setNextAnim(int)' on a null object reference
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:765)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
    at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

你知道我做错了什么会引发这次车祸吗?

最佳答案

看看例外情况:
java.lang.NullPointerException:尝试调用虚拟方法“void
空对象上的android.support.v4.app.fragment.setNextAnim(int)'
参考
而且堆栈跟踪不包含对代码的引用,我认为有理由假设它与代码的这一部分无关。
相反,它可能与某个视图被垃圾收集/清空,然后稍后尝试使用它,在一个空对象上调用show/hide或类似的命令有关。见this discussion

07-24 09:47