2016-05-22 70 views
0

我在我的應用程序中使用ViewPager在選項卡中顯示3個片段。下列崩潰被報道在開發控制檯沒有任何詳細的指針問題致命異常:使用ViewPager時出現java.lang.NullPointerException

錯誤:

Attempt to invoke virtual method 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference

而且下面是崩潰的細節 -

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference 
    at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1613) 
    at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:633) 
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143) 
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1177) 
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1025) 
    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545) 
    at android.view.View.measure(View.java:18880) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952) 
    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668) 
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:735) 
    at android.view.View.measure(View.java:18880) 
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716) 
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462) 
    at android.view.View.measure(View.java:18880) 
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716) 
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462) 
    at android.view.View.measure(View.java:18880) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952) 
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) 
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) 
    at android.view.View.measure(View.java:18880) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952) 
    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:18880) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952) 
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) 
    at android.view.View.measure(View.java:18880) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952) 
    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:18880) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952) 
    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:18880) 
    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) 

任何人都面臨着類似的問題,有什麼事情解決?

+2

發佈您的Java代碼在這裏。 – Ironman

+0

好心地張貼您的代碼,可能是一個問題,你如何使用FragmentManager和檢查此線程 http://stackoverflow.com/questions/34332900/android-support-v4-app-fragmentmanagerpopbackstackimmediate-results-in-a- null –

+0

post code,另一個建議是使用本教程http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/ – Manny265

回答

0

我也遇到過這個問題。我不知道在這種情況下是否使用Handler(android.os.handler)。如果你正在使用,那麼確保你已經在onCreate上初始化它。初始化後,我已經解決了這種類型的日誌貓錯誤

相關問題