Android 中的 ViewTreeObserver NullPointerException 崩溃

ViewTreeObserver NullPointerException Crash in Android

我的 viewTreeObserver 在 firebase 上崩溃了。可能的原因是什么? ViewTreeObserver 在应用程序的多个位置使用,因此不确定崩溃发生的确切位置

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void android.view.ViewTreeObserver$OnGlobalLayoutListener.onGlobalLayout()' on a null object reference
       at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:1056)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3050)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2075)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8471)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1065)
       at android.view.Choreographer.doCallbacks(Choreographer.java:889)
       at android.view.Choreographer.doFrame(Choreographer.java:816)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1050)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:7824)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:512)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1027)

如果应用程序保持对 ViewTreeObserver 的长期引用,则它应始终在调用任何其他方法之前检查 isAlive() 的结果。

https://developer.android.com/reference/android/view/ViewTreeObserver#isAlive()