Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException #653

Closed
330676687 opened this issue Nov 25, 2017 · 25 comments · Fixed by #782
Closed

java.lang.NullPointerException #653

330676687 opened this issue Nov 25, 2017 · 25 comments · Fixed by #782

Comments

@330676687
Copy link

330676687 commented Nov 25, 2017

开发者模式 不保留活动选项打开

A-B-C,其中B通过startWithPop启动C
在C界面home返回桌面,再回到app,返回A,就会崩溃
报错信息如下:

java.lang.NullPointerException
Attempt to invoke virtual method 'void android.support.v4.app.Fragment.setNextAnim(int)' on a null object reference
android.support.v4.app.BackStackRecord.executePopOps(TbsSdkJava:826)
android.support.v4.app.FragmentManagerImpl.executeOps(TbsSdkJava:2587)android.support.v4.app.FragmentManagerImpl.executeOpsTogether(TbsSdkJava:2377)
android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(TbsSdkJava:2332)
android.support.v4.app.FragmentManagerImpl.execPendingActions(TbsSdkJava:2239)
android.support.v4.app.FragmentManagerImpl$1.run(TbsSdkJava:700)
android.os.Handler.handleCallback(Handler.java:815)
android.os.Handler.dispatchMessage(Handler.java:104)
android.os.Looper.loop(Looper.java:200)
android.app.ActivityThread.main(ActivityThread.java:5856)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:987)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)

@YoKeyword
Copy link
Owner

根据你的描述,以及

java.lang.NullPointerException
Attempt to invoke virtual method 'void android.support.v4.app.Fragment.setNextAnim(int)' on a null object reference

猜测在页面重启后,你没有找回Fragment的引用,导致恢复时,Fragment是null

@330676687
Copy link
Author

这个崩溃是更新1.1.7之后才出现的 之前一直正常 1.1.8依然存在此问题

@YoKeyword
Copy link
Owner

和版本无关,这个异常很简单,就是Fragment是null,然后操作了Fragment

先定位到哪个页面 哪一行的代码引起的,因为可以复现,排查很简单那

@330676687
Copy link
Author

嗯嗯 那我再看看

@330676687 330676687 reopened this Nov 27, 2017
@330676687
Copy link
Author

已定位到原因,是因为官方的Fragment库更新了27
是否该库没有兼容27?

@YoKeyword
Copy link
Owner

@330676687 我看了下diff_report

没看到Fragment相关的改动, 稍晚我会升级到27测试下

你应该定位到发生异常的代码了吧, 贴下看看 尤其是onCreate()里初始化Fragment的代码

@330676687
Copy link
Author

刚测试了下demo v7升级到27 的确有我这个崩溃问题
问题发生在startWithPop

@YoKeyword
Copy link
Owner

OK 已复现,稍后兼容

@YoKeyword
Copy link
Owner

@330676687 暂时建议回退到v4-26.1.0

v27 该问题还不确定是否是官方BUG, 稍后会查看代码上的差异再看看

@330676687
Copy link
Author

好哒

@YoKeyword
Copy link
Owner

YoKeyword commented Nov 28, 2017

已修复,暂不发布,等一个支持Animator的新功能,这周发布v1.2.0

出现不兼容的原因在于:

 // FragmentManager.java:
 private void animateRemoveFragment(@NonNull final Fragment fragment,
            @NonNull AnimationOrAnimator anim, final int newState) {
                     ...
-                    if (fragment.getAnimatingAway() != null) {
-                        fragment.setAnimatingAway(null);
-                        moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, false);
-                    }
+                    // onAnimationEnd() comes during draw(), so there can still be some
+                    // draw events happening after this call. We don't want to detach
+                    // the view until after the onAnimationEnd()
+                    container.post(new Runnable() {
+                        @Override
+                        public void run() {
+                            container.endViewTransition(viewToAnimate);
+
+                            if (fragment.getAnimatingAway() != null) {
+                                fragment.setAnimatingAway(null);
+                                moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0,
+                                        false);
+                            }
+                        }
+                    });

Google把moveToState迁移到post队列里,导致在pop()+start()时 时间上存在冲突,dev分支上解决的commit

@YoKeyword
Copy link
Owner

@330676687 已发布 v1.1.9 兼容了27.0.0+ ,可以更新解决兼容问题

v1.2.0稍后发布

@zhenian
Copy link
Contributor

zhenian commented Dec 11, 2017

@YoKeyword 1.20 发布时间???

@YoKeyword
Copy link
Owner

@zhenian 最近工作较忙, v1.2.0还在测试中, 目前新增特性只有:支持Animator,发布时间暂时待定

@330676687
Copy link
Author

从1.1.9升到1.2.5之后 该崩溃又出现了,暂不知道如何复现

@YoKeyword
Copy link
Owner

1.2.X之后,因为队列机制,事务会独自运行,增强稳定性, Log贴一下哈

@330676687
Copy link
Author

看了log 跟上面贴的一模一样的呢,,, 行数都没变

@330676687
Copy link
Author

在4.4的测试机上复现出来了 复现步骤跟开头所描述一样:

开发者模式 不保留活动选项打开
A-B-C,其中B通过startWithPop启动C
在C界面home返回桌面,再回到app,返回A,就会崩溃

sdk版本为1.2.6

@330676687
Copy link
Author

该崩溃在bugly上出现了不少 只能暂时降级为1.1.10 希望能解决~

@YoKeyword YoKeyword reopened this Feb 23, 2018
YoKeyword added a commit that referenced this issue Feb 25, 2018
YoKeyword added a commit that referenced this issue Feb 25, 2018
@YoKeyword YoKeyword mentioned this issue Feb 25, 2018
Merged
@YoKeyword
Copy link
Owner

已修复v1.2.7

@gmfbilu
Copy link

gmfbilu commented May 3, 2018

1.3.3也出现这种问题,我的功能和你的demo中的左侧面板MenuListFragment和ContentFragment类似

@YoKeyword
Copy link
Owner

@gmfbilu #825

@NiceNicks
Copy link

1.3.7版本复现该问题 ,华为6.0 内存2G 开发者设置开启不保留后台活动 必现问题。

@NiceNicks
Copy link

image

现在只能是在根Activity 去掉这行了 被系统销毁时不去保存状态

@huangjide
Copy link

image

现在只能是在根Activity 去掉这行了 被系统销毁时不去保存状态

遇到同样问题,这样空实现,你这边没有其他问题的是吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants