android – 使用PagerAdapter的IllegalStateException

前端之家收集整理的这篇文章主要介绍了android – 使用PagerAdapter的IllegalStateException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在这个活动中得到一个IllegalStateException,但不能确定发生了什么.这是QuickContactActivity中的ViewPagerAdapter类.
private class ViewPagerAdapter extends FragmentPagerAdapter {
    public ViewPagerAdapter(FragmentManager fragmentManager) {
        super(fragmentManager);
    }

    @Override
    public Fragment getItem(int position) {
        QuickContactListFragment fragment = new QuickContactListFragment();
        final String mimeType = mSortedActionMimeTypes.get(position);
        final List<Action> actions = mActions.get(mimeType);
        fragment.setActions(actions);
        return fragment;
    }

    @Override
    public int getCount() {
        return mSortedActionMimeTypes.size();
    }
}

这是崩溃日志:

07-15 09:49:21.060: E/com.##.##.##.Application(12378): Thread uncaught exception:
07-15 09:49:21.060: E/com.##.##.##.Application(12378): 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/item_list_pager Pager class: class android.support.v4.view.ViewPager Problematic adapter: class com.##.contacts.quickcontact.QuickContactActivity$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)
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.FrameLayout.onMeasure(FrameLayout.java:310)
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.FrameLayout.onMeasure(FrameLayout.java:310)
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)
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.FrameLayout.onMeasure(FrameLayout.java:310)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
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.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.Choreographer.doFrame(Choreographer.java:532)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.os.Handler.handleCallback(Handler.java:725)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.os.Looper.loop(Looper.java:137)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at android.app.ActivityThread.main(ActivityThread.java:5041)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at java.lang.reflect.Method.invokeNative(Native Method)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at java.lang.reflect.Method.invoke(Method.java:511)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-15 09:49:21.060: E/com.##.##.##.Application(12378):  at dalvik.system.NativeStart.main(Native Method)
07-15 09:49:21.060: E/ACRA(12378): ACRA caught a IllegalStateException exception for com.##.##.android. Building report.

解决方法

问题是您在PageAdapter中显示的项目/页面列表发生变化,您不调用pageAdapter.notifyDataSetChanged().

如果您继续阅读该消息,则表示等待0个项目并获得1.这样,您可以设置适配器,然后再设置适配器接收到的所有项目/页面.

原文链接:https://www.f2er.com/android/310612.html

猜你在找的Android相关文章