E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: org.example.magnusluca.drawertestapp, PID: 3624
java.lang.NullPointerException: Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
没修改前代码:
public class OrderManagerFragmentPagerAdapter extends FragmentPagerAdapter { private FollowingResult.DataEntity.CountEntity countEntity; public OrderManagerFragmentPagerAdapter(FragmentManager fm, FollowingResult.DataEntity.CountEntity countEntity) { super(fm); this.countEntity = countEntity; } @Override public void destroyItem(ViewGroup container, int position, Object object) { //super.destroyItem(container, position, object); } @Override public Fragment getItem(int position) { OrderManagerFragment badgeRefreshListener = OrderManagerFragment .this; String strTabTitle = TITLES[position]; switch (strTabTitle) { case "新订单": return NewOrderFragment.newInstance(badgeRefreshListener); case "跟踪中": return NewOrderFragment.newInstance(badgeRefreshListener); case "转出": return NewOrderFragment.newInstance(badgeRefreshListener); case "成交": return NewOrderFragment.newInstance(badgeRefreshListener); case "流失": return NewOrderFragment.newInstance(badgeRefreshListener); case "无效": return NewOrderFragment.newInstance(badgeRefreshListener); default: return null; } } @Override public CharSequence getPageTitle(int position) { return TITLES[position % TITLES.length]; } @Override public int getCount() { return TITLES.length; } }
出问题主要出现在标红的地方,代码修改过为
return new NewOrderFragment();
问题解决
*上面解决方案:http://*.com/questions/26822516/how-to-display-3-fragments-inside-pageviewer