Я играю с MotionLayout и получил странную проблему
Когда я изменил версию используемой библиотеки с com.android.support.constraint:constraint-layout:2.0.0-alpha2
на com.android.support.constraint:constraint-layout:2.0.0-alpha3
мое приложение упало:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ru.sergik.collapsibleexoplayer, PID: 1376
java.lang.NullPointerException: Attempt to invoke virtual method 'int androidx.constraintlayout.motion.widget.MotionScene.getDuration()' on a null object reference
at androidx.constraintlayout.motion.widget.MotionLayout.dispatchDraw(MotionLayout.java:1634)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2072)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.draw(View.java:20373)
at com.android.internal.policy.DecorView.draw(DecorView.java:980)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:800)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3496)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3283)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2818)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1780)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7827)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Выполняя некоторую отладку, я обнаружил некоторые различия в версиях MotionLayout, вызывающие этот сбой:
Как вы можете видеть в альфа-3, будет вызываться this.mDevModeDraw.draw(canvas, this.mFrameArrayList, this.mScene.getDuration(), this.mDebugPath);
и вызывать сбой при попытке получить продолжительность сцены движения this.mScene.getDuration()
, но в альфа-2 он не будет вызываться из-за другого условия if.
Как мне решить эту проблему?