Android-Bugs-[2016-April]

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容