0

实际上,我在代码中使用了共享元素转换。友盟抓到的错误日志是:

java.lang.NullPointerException:尝试在 android.app.ActivityTransitionCoordinator.null setSharedElementMatrices(null)(ActivityTransitionCoordinator.java: 505) 在 android.app.ActivityTransitionCoordinator.null moveSharedElementsToOverlay(null)(ActivityTransitionCoordinator.java:794) 在 android.app.EnterTransitionCoordinator$3.null onPreDraw(null)(EnterTransitionCoordinator.java:204) 在 android.view.ViewTreeObserver.null dispatchOnPreDraw (null)(ViewTreeObserver.java:944) 在 android.view.ViewRootImpl.null performTraversals(null)(ViewRootImpl.java:2055) 在 android.view.ViewRootImpl.null doTraversal(null)(ViewRootImpl.java:1107) 在 android 。看法。ViewRootImpl$TraversalRunnable.null run(null)(ViewRootImpl.java:6013) at android.view.Choreographer$CallbackRecord.null run(null)(Choreographer.java:858) at android.view.Choreographer.null doCallbacks(null)( Choreographer.java:670) at android.view.Choreographer.null doFrame(null)(Choreographer.java:606) at android.view.Choreographer$FrameDisplayEventReceiver.null run(null)(Choreographer.java:844) at android.os .Handler.null handleCallback(null)(Handler.java:739) at android.os.Handler.null dispatchMessage(null)(Handler.java:95) at android.os.Looper.null loop(null)(Looper.java :148) 在 android.app.ActivityThread.null main(null)(ActivityThread.java:5417) 在 java.lang.reflect.Method.null 调用(null)(Method.java) 在 com.android.internal.os。 ZygoteInit$MethodAndArgsCaller.null run(null)(ZygoteInit.java:726) 在 com.android.internal.os.ZygoteInit.null main(null)(ZygoteInit.java:616)

我查看了设备的版本,没有居中,包括6.0、7.0和8.0。并且设备型号也没有居中。

这是我的代码:

override fun onLoadUrl(url: String, source: String, imageView: ImageView?, drawableRes: Int) {
        val tabBean = MultiWindowManager.getForegroundTab()!!
        val transaction = supportFragmentManager
                .beginTransaction()
        var fragment = supportFragmentManager
                .findFragmentByTag(tabBean.tabId) as? WebFragment
        if (fragment != null) {
            transaction.show(fragment).commitAllowingStateLoss()
            fragment.loadUrl(url, source)
        } else {
            fragment = WebFragment.newInstance(url, tabBean.tabId, source, drawableRes)
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                fragment.sharedElementEnterTransition = DetailTransition()
                fragment.exitTransition = Fade()
                fragment.enterTransition = Fade()
                fragment.sharedElementReturnTransition = DetailTransition()
            }
            transaction.remove(mainFragment)
            transaction.add(R.id.frameContainer, fragment, tabBean.tabId)
            imageView?.let {
                transaction.addSharedElement(it, getString(R.string.shared_recommend))
            }
            transaction.commitAllowingStateLoss()
        }
        webFragment = fragment
        updateFragmentType(FRAGMENT_WEB)
    }

DetailTransition.java:

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class DetailTransition extends TransitionSet {
    public DetailTransition() {
        init();
    }

    public DetailTransition(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        setOrdering(ORDERING_TOGETHER);
        addTransition(new ChangeBounds()).
                addTransition(new ChangeTransform()).
                addTransition(new ChangeImageTransform());
    }
}

我希望我再也看不到这个错误。

4

1 回答 1

0

谷歌播放服务可能必须在您的构建系统上更新,我遇到了类似的问题,QR 扫描仪在通过 gradle build 更新播放服务之前无法工作,然后根本不存在类似的异常。

于 2019-10-09T09:24:00.160 回答