异常:IllegalStateException: The application's PagerAdapter changed the adapter's contents

来源:互联网 发布:淘宝心级怎么算买家 编辑:程序博客网 时间:2024/04/30 09:45

先把异常贴出来:

java.lang.IllegalStateException: 
The application's PagerAdapter changed the adapter's contents 
without calling PagerAdapter#notifyDataSetChanged!
 Expected adapter item count: 0, found: 3 Pager id: 
cn.ronghuakeji.application:id/view_pagerContent 
Pager class: class android.support.v4.view.ViewPager Problematic 
adapter: class cn.itcast.application.phone_sms.ui.adapter.ContentViewPagerAdapter


这是我在我在fragment中设置viewPager时出现的问题,因为我将fragment和viewpager页,都抽取了相关的基类,在编写的时候脑子出现了混乱,所以出现了这个问题。


解决方法:

在初始化ViewPager时,应先给Adapter初始化内容后再将该adapter传给ViewPager,如果不这样处理,在更新adapter的内容后,应该调用一下adapter的notifyDataSetChanged方法,否则在ADT22以上使用会报The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged的异常,具体原因可参考:http://stackoverflow.com/questions/16756131/fragmentstatepageradapter-stopped-working-after-updating-to-adt-22


0 0
原创粉丝点击