0

以下のようなエラーが表示され、なぜ発生しているのかわかりません。私はこのエラーについてさらに詳しい情報を持っていません。Android PagerAdapter FragmentActivityのIllegalStateException

私はAndroid ListViewに50個のアイテムがあります。アイテムをクリックして第2画面(ページャを使用したフラグメントアクティビティ)を開くと、このフラグメントアクティビティは、左または右のスワイプ可能性を持つ最後のアイテムまでListViewのクリックされたアイテムからフラグメント内のすべてのアイテムを表示します。

java.lang.IllegalStateException: 
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1167) 
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1116) 
    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642) 
    at android.view.View.measure(View.java:17951) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5797) 
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
    at android.view.View.measure(View.java:17951) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5797) 
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) 
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) 
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) 
    at android.view.View.measure(View.java:17951) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5797) 
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:436) 
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2910) 
    at android.view.View.measure(View.java:17951) 
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2048) 
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1185) 
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1406) 
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1073) 
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5988) 
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) 
    at android.view.Choreographer.doCallbacks(Choreographer.java:580) 
    at android.view.Choreographer.doFrame(Choreographer.java:550) 
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) 
    at android.os.Handler.handleCallback(Handler.java:739) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5910) 
    at java.lang.reflect.Method.invoke(Native Method:0) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 
+1

あなたのフラグメントのコードを貼り付けることはできますか? –

+0

@AmitKumarはコードをいくつか追加しました。 – Yakari

答えて

0
public class ScreenSlidePagerActivity extends FragmentActivity { 
    /** 
    * The number of pages (wizard steps) to show in this demo. 
    */ 
    public static int NUM_PAGES = 50; 

    /** 
    * The pager widget, which handles animation and allows swiping horizontally to access previous 
    * and next wizard steps. 
    */ 
    private ViewPager mPager; 

    /** 
    * The pager adapter, which provides the pages to the view pager widget. 
    */ 
    private PagerAdapter mPagerAdapter; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_screen_slide); 

     // Instantiate a ViewPager and a PagerAdapter. 
     mPager = (ViewPager) findViewById(R.id.pager); 
     mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); 
     mPager.setAdapter(mPagerAdapter); 

    } 

    @Override 
    public void onBackPressed() { 
     if (mPager.getCurrentItem() <= 0) { 

      //start an intent 
     } else { 
      // Otherwise, select the previous step. 
      mPager.setCurrentItem(mPager.getCurrentItem() - 1); 
     } 
    } 

    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 
     public ScreenSlidePagerAdapter(FragmentManager fm) { 
      super(fm); 
     } 

     @Override 
     public Fragment getItem(int position) { 

      Bundle bundle = new Bundle(); 
      bundle.putSerializable("content", "bla bla content"); 

      MyFragment fragmentObj= new MyFragment(); 
      fragmentObj.setArguments(bundle); 
      return fragmentObj; 
     } 

     @Override 
     public int getCount() { 
      return NUM_PAGES; 
     } 

    } 


} 
関連する問題