A界面中有viewpager的动态加载,从界面A跳到界面B,再finish掉B返回A时报出此异常。
java.lang.IllegalStateException:
The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!
Expected adapter item count: 0, found: 1 Pager id: com.##.##.android:id/vp_pager Pager class: class android.support.v4.view.ViewPager Problematic adapter: class com.##.contacts.quickcontact.Activity$ViewPagerAdapter 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.support.v4.view.ViewPager.populate(ViewPager.java:959) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.support.v4.view.ViewPager.populate(ViewPager.java:911) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1432) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.view.View.measure(View.java:15518) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 07-15 09:49:21.060: E/com.##.##.##.Application(12378): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
我的解决办法是
在界面A的onResume()方法中调用这个viewpager的adapter.notifyDataSetChanged()方法,这样就OK了