ViewPager FragmentPagerAdapter Nullpointer

前端 未结 3 440
说谎
说谎 2020-12-08 07:04

I got this error by using the ViewPager in the Android Support package. from the Horizontal View Swiping with ViewPager Tutorial

06-19 13:07:25.950: E/Andro         


        
相关标签:
3条回答
  • 2020-12-08 07:27

    If getItem() in your Adapter returns null that can cause a null pointer exception.

    0 讨论(0)
  • 2020-12-08 07:30

    It's a simple solution. I mixed android.app.Fragment and android.support.v4.app.Fragment

    hope this helps someone

    0 讨论(0)
  • 2020-12-08 07:43

    Just in case anyone doesn't read the comments of passsy's answer, here is a summary of the useful answers:

    1) Examine your getItem(int index) method very closely and look for any logic, scenarios or missing 'break' statements which might cause you to end up with a null fragment.

    2) Check that the count returned by getCount() matches the number of fragments returned in getItem(int index).

    3) Examine your imports and ensure you aren't mixing android.app.Fragment with android.support.v4.app.Fragment

    0 讨论(0)
提交回复
热议问题