title: No View found for id X for Fragment Y
body: <p>I'm attempting to use fragments to give a different display depending on whether the app is being run on a phone or a tablet - as fragments are supposed to be used.</p>
  
  <p>I have the following XML for my layouts:</p>
  
  <p>layout/main.xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"  &gt;
  
      &lt;RelativeLayout
          android:id="@+id/list_fragment_view"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>layout-large/main.xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" 
      android:orientation="horizontal"
      android:baselineAligned="false" &gt;
  
      &lt;RelativeLayout
          android:id="@+id/list_fragment_view"
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="2" /&gt;
  
      &lt;RelativeLayout
          android:id="@+id/sales_agreement_fragment_view"
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="7" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I havetried using FrameLayouts instead of the RelativeLayouts in the second example - it didn't seem to make any difference.</p>
  
  <p>My Activity onCreate() code is as follows:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          FragmentManager manager = getFragmentManager();
          View salesAgreementLayout = findViewById(R.id.sales_agreement_fragment_view);
          Fragment formsListFragment = new KingdomSpasFormsListFragment();
  
          FragmentTransaction fragmentTransaction = manager.beginTransaction();
          fragmentTransaction.add(R.id.list_fragment_view,formsListFragment);
          if (salesAgreementLayout != null) {
              Fragment salesAgreementFragment = new SalesAgreementFragment();
              fragmentTransaction.add(R.id.sales_agreement_fragment_view, salesAgreementFragment);
          }
  
          fragmentTransaction.commit();
  
      }
  </code></pre>
  
  <p>However, running this (whether on a phone or a tablet results in the following error:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kingdomspas.android.kingdomspasforms/com.kingdomspas.android.kingdomspasforms.activities.KingdomSpasFormsActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f070000 (com.kingdomspas.android.kingdomspasforms:id/list_fragment_view) for fragment KingdomSpasFormsListFragment{527f671c #0 id=0x7f070000}
  </code></pre>
  
  <p>I've Googled this extensively as it seems to be a common problem.  The main solution, however, seem to be that the original layout specified in setContentView() doesn't contain the Views later referenced in the add() methods.  However, this is definitely not the problem in my case (unless I'm being ridiculously blind - I've checked and re-checked).</p>
  
  <p>In fairness, I'm not actually certain that this is the best UI design for my app - I'm wondering about tabs perhaps - but, either way, I'd really like to understand what the problem is here and what I'm doing wrong - else I'm likely doomed to repeat it in the future.</p>