Android-Bugs-[2016-April]

2016-04-28  本文已影响0人  湫刀鱼

Exception Log:##

java.lang.IllegalStateException:   
The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! 
Expected adapter item count: 4, found: 13 Pager id: <PackageName>:id/view_pager Pager class:class 
com.geo.smallcredit.view.loopingpager.LoopViewPager Problematic adapter: 
class com.geo.smallcredit.view.loopingpager.LoopPagerAdapterWrapper

应用程序的 PagerAdapter 更改适配器的内容而无需调用 PagerAdapter #notifyDataSetChanged !
系统跟踪count的值,如果这个值和getCount返回的值不一致,就会抛出这个异常。

另外如果你使用了LoopingViewPager这个使用包装设计方式实现无限循环的ViewPager的话,是不能通过notifyDataSetChanged方法来刷新数据的,因为每次真正的PagerAdapter中的 N [N=adapter.getCount()]和mExpectedAdapterCount是不相等的
报错处:

void populate(int newCurrentItem){
   ...
   #final int N = mAdapter.getCount();#
   final int endPos = Math.min(N-1, mCurItem + pageLimit);
   if (N != mExpectedAdapterCount) {
      String resName;
      try {
         resName = getResources().getResourceName(getId());
      } catch (Resources.NotFoundException e) {
         resName = Integer.toHexString(getId());
      }
      throw new IllegalStateException("The application's PagerAdapter changed the adapter's" +
      " contents without calling PagerAdapter#notifyDataSetChanged!" +
      " Expected adapter item count: " + mExpectedAdapterCount + ", found: " + N +
      " Pager id: " + resName + " Pager class: " + getClass() + " Problematic adapter: " + 
      mAdapter.getClass());
   ...
}

如果只是使用了基本的ViewPager+PagerAdapter的话,导致的原因就是因为Adapter没有刷新。

Solutions##

http://stackoverflow.com/questions/16756131/fragmentstatepageradapter-stopped-working-after-updating-to-adt-22

上一篇 下一篇

猜你喜欢

热点阅读