title: Fragment not attached to Activity
body: <p>I have activity with TabLayot.</p>
  
  <pre><code>public class MapTab extends AppCompatActivity {
  
  private Toolbar toolbar;
  private TabLayout tabLayout;
  private ViewPager viewPager;
  
  
  public MapTab() {
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_map_tab);
  
      toolbar = (Toolbar)findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
      viewPager = (ViewPager)findViewById(R.id.viewPager);
      setupViewPager(viewPager);
  
      tabLayout = (TabLayout)findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(viewPager);
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
      adapter.addFragment(new PvPMap(), "PvP Карты");
      adapter.addFragment(new PvEMap(), "PvE Карты");
      viewPager.setAdapter(adapter);
  }
  
  class ViewPagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
      public ViewPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      public void addFragment(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  }
  </code></pre>
  
  <p>XML</p>
  
  <pre><code>&lt;android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      &gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:layout_scrollFlags = "scroll|enterAlways"
          /&gt;
      &lt;android.support.design.widget.TabLayout
          android:id="@+id/tabs"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          app:tabMode="fixed"
          app:tabGravity="center"
          /&gt;
  &lt;/android.support.design.widget.AppBarLayout&gt;
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/viewPager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      /&gt;
  </code></pre>
  
  <p>In first Tab, ListFragment</p>
  
  <pre><code>public class PvPMap extends ListFragment {
  
  Fragment permafrost;
  Fragment river;
  Fragment reactor;
  Fragment oil;
  Fragment mountain;
  Fragment island;
  Fragment cold;
  Fragment pis;
  Fragment fire;
  Fragment air;
  
  FragmentManager manager;
  FragmentTransaction transaction;
  
  
  String [] mapname = new String[] {"Вечная мерзлота","Тихая река","Реактор","Нефтепровод","Предгорье",
          "Затеряный остров","Холодная сталь","Мирный рубеж","Горящий песок","Воздушная тревога"};
  int [] mapimg = new int[] {R.drawable.permafrost, R.drawable.river, R.drawable.reaktor, R.drawable.oil, R.drawable.mauntain,
          R.drawable.island, R.drawable.cold, R.drawable.pis, R.drawable.fire, R.drawable.air};
  String [] mapinfo = new String[] {getResources().getString(R.string.permafrostInfo), getResources().getString(R.string.riverInfo),
          getResources().getString(R.string.reaktorInfo), getResources().getString(R.string.oilInfo),
          getResources().getString(R.string.mauntainInfo), getResources().getString(R.string.islandInfo),
          getResources().getString(R.string.coldInfo), getResources().getString(R.string.pisInfo),
          getResources().getString(R.string.fireInfo), getResources().getString(R.string.airInfo),};
  
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View pvp = inflater.inflate(R.layout.layout_pvp, container, false);
  
      permafrost = new Permafrost();
      river = new River();
      reactor = new Reactor();
      oil = new Oil();
      mountain = new Mauntain();
      island = new Island();
      cold = new Cold();
      pis = new Pis();
      fire = new Fire();
      air = new Air();
  
      List&lt;HashMap&lt;String, String&gt;&gt; aList =  new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      for (int i = 0; i &lt; mapname.length; i++){
          HashMap&lt;String, String&gt; m = new HashMap&lt;String,String&gt;();
          m.put("name", mapname[i]);
          m.put("info", mapinfo[i]);
          m.put("img", Integer.toString(mapimg[i]));
          aList.add(m);
      }
  
      String[] from = {"name", "info", "img"};
  
      int [] to = {R.id.textViewMap, R.id.textViewInfo, R.id.imageViewMap};
  
      SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.list_item, from, to);
  
      setListAdapter(adapter);
  
      return pvp;
  }
  
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
      super.onListItemClick(l, v, position, id);
      manager = getChildFragmentManager();
      transaction = manager.beginTransaction();
  
      switch (position){
          case 0:
              transaction.replace(R.id.container, permafrost);
              transaction.addToBackStack(null);
              break;
          case 1:
              transaction.replace(R.id.container, river);
              transaction.addToBackStack(null);
              break;
          case 2:
              transaction.replace(R.id.container, reactor);
              transaction.addToBackStack(null);
              break;
          case 3:
              transaction.replace(R.id.container, oil);
              transaction.addToBackStack(null);
              break;
          case 4:
              transaction.replace(R.id.container, mountain);
              transaction.addToBackStack(null);
              break;
          case 5:
              transaction.replace(R.id.container, island);
              transaction.addToBackStack(null);
              break;
          case 6:
              transaction.replace(R.id.container, cold);
              transaction.addToBackStack(null);
              break;
          case 7:
              transaction.replace(R.id.container, pis);
              transaction.addToBackStack(null);
              break;
          case 8:
              transaction.replace(R.id.container, fire);
              transaction.addToBackStack(null);
              break;
          case 9:
              transaction.replace(R.id.container, air);
              transaction.addToBackStack(null);
              break;
  
      }
      transaction.commit();
  }
  </code></pre>
  
  <p>In secondary only text.</p>
  
  <p>When I go to activity with TabLayout  an error occurs:</p>
  
  <pre><code>06-15 16:52:09.520 29302-29302/com.example.roman.armoredwarfare E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                Process: com.example.roman.armoredwarfare, PID: 29302
                                                                                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.roman.armoredwarfare/com.example.roman.armoredwarfare.MapTab}: java.lang.IllegalStateException: Fragment PvPMap{11d5eb92} not attached to Activity
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608)
                                                                                    at android.app.ActivityThread.access$800(ActivityThread.java:178)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:111)
                                                                                    at android.os.Looper.loop(Looper.java:194)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5637)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
                                                                                 Caused by: java.lang.IllegalStateException: Fragment PvPMap{11d5eb92} not attached to Activity
                                                                                    at android.support.v4.app.Fragment.getResources(Fragment.java:636)
                                                                                    at com.example.roman.armoredwarfare.PvPMap.&lt;init&gt;(PvPMap.java:55)
                                                                                    at com.example.roman.armoredwarfare.MapTab.setupViewPager(MapTab.java:47)
                                                                                    at com.example.roman.armoredwarfare.MapTab.onCreate(MapTab.java:39)
                                                                                    at android.app.Activity.performCreate(Activity.java:6092)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608) 
                                                                                    at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:111) 
                                                                                    at android.os.Looper.loop(Looper.java:194) 
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5637) 
                                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959) 
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754) 
  </code></pre>
  
  <p>Specifically 1:</p>
  
  <pre><code>String [] mapinfo = new String[] {getResources().getString(R.string.permafrostInfo), getResources().getString(R.string.riverInfo),
          getResources().getString(R.string.reaktorInfo), getResources().getString(R.string.oilInfo),
          getResources().getString(R.string.mauntainInfo), getResources().getString(R.string.islandInfo),
          getResources().getString(R.string.coldInfo), getResources().getString(R.string.pisInfo),
          getResources().getString(R.string.fireInfo), getResources().getString(R.string.airInfo),};
  </code></pre>
  
  <p>in Fragment with ListFragment</p>
  
  <p>2:<code>setupViewPager(viewPager);</code></p>
  
  <p>3:<code>adapter.addFragment(new PvPMap(), "PvP Карты");</code></p>
  
  <p>in activity with TabLayot</p>
  
  <p>My English is not so good, excuse me.</p>