码迷,mamicode.com
首页 > 移动开发 > 详细

Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference

时间:2016-08-09 20:34:17      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

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();
问题解决

stackoverflow上面解决方案:http://stackoverflow.com/questions/26822516/how-to-display-3-fragments-inside-pageviewer

 

Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference

标签:

原文地址:http://www.cnblogs.com/androidsuperman/p/5754288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!