title: IllegalStateException: The application's PagerAdapter changed the adapter's content without calling PagerAdapter#notifyDataSetChanged
body: <p>I'm using the <code>ViewPager</code> example with <code>ActionBar</code> tabs taken from the Android documentation <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html">here</a>.</p>
  
  <p>Unfortunately, as soon as I call the <code>addTab</code> method, the application crashes with the following exception:</p>
  
  <blockquote>
    <p>IllegalStateException: The application's PagerAdapter changed the
    adapter's content without calling PagerAdapter#notifyDataSetChanged!
    Expected adapter item count 0, found 1.</p>
  </blockquote>
  
  <p>This is the <code>FragmentPagerAdapter</code> code:</p>
  
  <pre><code>public static class TabsAdapter extends FragmentPagerAdapter
              implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
          private final Context mContext;
          private final ActionBar mActionBar;
          private final ViewPager mViewPager;
          private final ArrayList&lt;TabInfo&gt; mTabs = new ArrayList&lt;TabInfo&gt;();
  
          static final class TabInfo {
              private final Class&lt;?&gt; clss;
              private final Bundle args;
  
              TabInfo(Class&lt;?&gt; _class, Bundle _args) {
                  clss = _class;
                  args = _args;
              }
          }
  
          public TabsAdapter(Activity activity, ViewPager pager) {
              super(activity.getFragmentManager());
              mContext = activity;
              mActionBar = activity.getActionBar();
              mViewPager = pager;
              mViewPager.setAdapter(this);
              mViewPager.setOnPageChangeListener(this);
          }
  
          public void addTab(ActionBar.Tab tab, Class&lt;?&gt; clss, Bundle args) {
              TabInfo info = new TabInfo(clss, args);
              tab.setTag(info);
              tab.setTabListener(this);
              mTabs.add(info);
              mActionBar.addTab(tab);
              notifyDataSetChanged();
          }
  
          @Override
          public int getCount() {
              return mTabs.size();
          }
  
          @Override
          public Fragment getItem(int position) {
              TabInfo info = mTabs.get(position);
              return Fragment.instantiate(mContext, info.clss.getName(), info.args);
          }
  
          @Override
          public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
          }
  
          @Override
          public void onPageSelected(int position) {
              mActionBar.setSelectedNavigationItem(position);
          }
  
          @Override
          public void onPageScrollStateChanged(int state) {
          }
  
          @Override
          public void onTabSelected(Tab tab, FragmentTransaction ft) {
              Object tag = tab.getTag();
              for (int i=0; i&lt;mTabs.size(); i++) {
                  if (mTabs.get(i) == tag) {
                      mViewPager.setCurrentItem(i);
                  }
              }
          }
  
          @Override
          public void onTabUnselected(Tab tab, FragmentTransaction ft) {
          }
  
          @Override
          public void onTabReselected(Tab tab, FragmentTransaction ft) {
          }
      }
  }
  </code></pre>
  
  <p>I'm not modifying my adapter in any other part of my code and I'm calling the <code>addTab</code> method from the main thread, the <code>addTab</code> method ends with a call to <code>notifyDataSetChanged</code>. As the documentation recommends to do:</p>
  
  <blockquote>
    <p>PagerAdapter supports data set changes. Data set changes must occur on
    the main thread and must end with a call to notifyDataSetChanged()
    similar to AdapterView adapters derived from BaseAdapter.</p>
  </blockquote>