在调用getVisibility()时ContentFrameLayout.onMeasure NPE

时间:2016-08-16 06:29:04

标签: android android-viewpager android-appcompat android-tablayout android-framelayout

我的应用的Crashlytics数据显示FrameLayout.onMeasure()上出现Null Pointer异常崩溃。

我无法在日志中看到我的应用程序跟踪,因此无法确定哪个活动正在崩溃,但主要活动包含一个带有5个碎片的TabLayout + Viewpager。 崩溃日志如下:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:193)
   at android.support.v7.widget.ContentFrameLayout.onMeasure(SourceFile:135)
   at android.view.View.measure(View.java:18866)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
   at android.view.View.measure(View.java:18866)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
   at android.view.View.measure(View.java:18866)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
   at android.view.View.measure(View.java:18866)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
   at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2650)
   at android.view.View.measure(View.java:18866)
   at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2104)
   at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1220)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1456)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1111)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6017)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
   at android.view.Choreographer.doCallbacks(Choreographer.java:670)
   at android.view.Choreographer.doFrame(Choreographer.java:606)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:224)
   at android.app.ActivityThread.main(ActivityThread.java:5526)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

这可能是AppCompat v7库中的一些错误吗? 或者我对Tablayout + Viewpager组合做错了什么

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

从日志中可以看出错误:

Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference

您正在尝试调用空对象上的方法,这会抛出空指针异常。
我的猜测是,你试图在getVisiblity()方法上获得onMeasure()对象的可见性,并且因为该对象尚未实例化(换句话说,保持空引用)它抛出了异常。

我在 ViewPager 上遇到了类似的情况。基本上,我还没有刷过/移动到特定的视图,因为那个视图还没有构建,我在它上面调用了一个方法,因此崩溃了应用程序。

您可以发布包含 onMeasure()部分的代码段,以便我可以帮您调试吗?

此致