java.lang.IllegalStateException: Can't change tag of fragment

It's probably because you're adding the same fragment instance three times to the list. You should create a new instance for each page.

Also, I suggest looking into FragmentStatePagerAdapter if you're not too far into development. It may be a better choice if you want to refresh the content of the fragments from the main activity.


The following method should return one fragment for each tab:

@Override
public Fragment getItem(int position) {
    //Add some code
    //to verify that it will not return null
    return listFragment.get(position);
}

The code is fine, but make sure that the listFragment contains three different Fragment's, and the fragment is not null.


It is probably, you are sending the fragment instance null. Never ever send the fragment instance null.

    public static MyFragment getInstance() {
    MyFragment myFragment = new MyFragment();
    return myFragment;
}

And In pager adapter always use the @Override public Fragment getItem(int position) { return fragments[position]; }

or

  @Override
public Fragment getItem(int position) {
    return fragments.get(position);
}

as per your list of fragment. Also please prefer the link FragmentPagerAdapter

Notes :- Never ever use context memory as a static