1. Bug问题所在
- ViewPager为null或者TabLayout为null
2. Bug出现场景
- TabLayout+ViewPager包裹Fragment
- Fragment里面又嵌套了TabLaytou+ViewPager包裹Fragment
- 里层或者外层的Fragment的Adaper继承的是FragmentStatePagerAdaper
3. Bug解决办法
- 里层和外层的Fragment都使用FragmentPagerAdaper(个人测试OK)
- 在Fragment的Adapter中重写以下方法
@Override
public void finishUpdate(ViewGroup container) {
try{
super.finishUpdate(container);
} catch (NullPointerException nullPointerException){
System.out.println("Catch the NullPointerException in FragmentPagerAdapter.finishUpdate");
}
}
本文介绍了解决在使用TabLayout与ViewPager包裹Fragment时遇到的NullPointerException问题的方法。该问题通常出现在内外层Fragment均使用FragmentStatePagerAdapter的情况下。文中提供了一个解决方案:采用FragmentPagerAdapter,并在Adapter中捕获并处理NullPointerException。
3523

被折叠的 条评论
为什么被折叠?



