Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the reason of the error is that your MainActivity was destroyed and then being recreated by Android OS.</p> <p>That means fragments list will be created again in your MainActivity.onCreate() method, but PagerAdapter will not use those fragments, instead it will use instances of fragments that was restored for you by FragmentManager (e.g. PagerAdapter.getItem() will not be called). And since instance of FirstFragment from your fragments list is not used it will not receive a call to FirstFragment.onCreateView() and mAdapter instance will stil be null then you'll call FirstFragment.load() method.</p> <p>The easiest (but not very good) way to fix this issue is to suppress restoring of your fragments by passing null as savedInstanceState param in MainActivity.onCreate():</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(null); ... } </code></pre> <p>Another way to go is to create fragments in your PagerAdapter on demand:</p> <pre><code>@Override public Fragment getItem(int position) { switch (position) { case 0: return Fragment.instantiate(this, Fragment1.class.getName()); case 1: return Fragment.instantiate(this, Fragment2.class.getName()); default: throw new RuntimException(); } } </code></pre> <p>and storing instances of fragments this way:</p> <pre><code>@Override public Object instantiateItem(View container, int position) { Fragment fr = (Fragment) super.instantiateItem(container, position); fragments[position] = fr; return fr; } </code></pre> <p>(Note: second way was not tested by me, so it may not work)</p> <p>BTW, you can check "Don't keep activities" developer option in your Android 4.0 settings to test such issues.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload