title: "no view found for id for fragment" error before onCreateView() called
body: <p>This is related to several posts, but I don't see anything that explains the order of view creation in the view hierarchy (static - xml and dynamic - in code).</p>
  
  <p>I have a FragmentActivity hosting an Activity and a Fragment.  I'm getting a runtime error from a view not being created for the fragment before the fragment's onCreateView is called. It's difficult to determine what the calling method is that can't find the view as the debugger can't seem to find the right line-numbers during step-through.  </p>
  
  <p>I can't get the source to attach correctly to see inside FragmentManager as there seems to be a mismatch between the dl'd source and .jar</p>
  
  <p>I placed a Log.i entry in StreamingActivity.onCreateView and the error occurs before that. </p>
  
  <p>Here is the relevant LogCat:</p>
  
  <pre><code>07-19 10:13:36.091: I/StreamingActivity(9886): onCreate
  07-19 10:13:42.271: W/dalvikvm(9886): threadid=1: thread exiting with uncaught exception (group=0x40020560)
  07-19 10:13:42.281: E/AndroidRuntime(9886): FATAL EXCEPTION: main
  07-19 10:13:42.281: E/AndroidRuntime(9886): java.lang.RuntimeException: Unable to start activity   
  ComponentInfo{kesten.fragmentstestbed/kesten.fragmentstestbed.FragmentsMainActivity}:        
  java.lang.IllegalArgumentException: No view found for id 0x7f05002e for fragment 
  StreamingActivity{4052f810 #0 id=0x7f05002e}
  caused by
  java.lang.IllegalArgumentException: No view found for id 0x7f05002e for fragment 
  StreamingActivity{40530948 #0 id=0x7f05002e}
  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:865)
  </code></pre>
  
  <p>my java file snippets:</p>
  
  <pre><code>public class FragmentsMainActivity extends FragmentActivity {
  
  public final static int STARTUP_ACTIVITY_RESULT=0;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_fragments_main);
  
      if(savedInstanceState == null) {
          Intent intentStartupActivity = new Intent(this, StartupActivity.class);
          if(intentStartupActivity != null)
              startActivityForResult(intentStartupActivity, STARTUP_ACTIVITY_RESULT);
  
          // get an instance of FragmentTransaction from your Activity
          FragmentTransaction fragmentTransaction = 
                  getSupportFragmentManager().beginTransaction();
  
          //add a fragment
          StreamingActivity streamingActivity = new StreamingActivity();
          if (streamingActivity != null) {
              fragmentTransaction.add(R.id.streamingactivity, streamingActivity);
              fragmentTransaction.commit();
          }
      }
  }
  </code></pre>
  
  <p>my Fragment:</p>
  
  <pre><code>public class StreamingActivity extends Fragment {
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Log.i("StreamingActivity","onCreate")   
  }
  </code></pre>
  
  <p>my layout files:
  "res/layout/main.xml"</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      &gt;
  
      &lt;FrameLayout
      android:id="@+id/streamingactivity"
      android:layout_width="0px"
      android:layout_height="match_parent"&gt;
  &lt;/FrameLayout&gt;
  
  
  &lt;!-- IMU --&gt;
  &lt;TextView
      android:id="@+id/imu_label"
      style="@style/Label.Title"
      android:text="@string/imu"
      /&gt;
  
  &lt;kesten.fragmentstestbed.ImuView
      android:id="@+id/imu_values"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/imu_label"
      android:text=""
      /&gt;
  
  &lt;!-- Accelerometer --&gt;
  &lt;TextView
      android:id="@+id/accelerometer_label"
      style="@style/Label.Title"
      android:text="@string/accelerometer"
      android:layout_below="@+id/imu_values"
      /&gt;
  
  &lt;!-- Filtered --&gt;
  &lt;kesten.fragmentstestbed.CoordinateView
      android:id="@+id/accelerometer_filtered_coordinates"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/accelerometer_label"
      android:text="@string/filtered"
      /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>and "activity_fragments_main.xml" for my FragmentActivity</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;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:padding="@dimen/padding_medium"
          android:text="@string/hello_world"
          tools:context=".FragmentsMainActivity" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Possible causes of id not found error gleaned from other Stackoverflow threads:</p>
  
  <ul>
  <li>wrong layout in setContentView() of the onCreate() method of the FragmentActivity.</li>
  </ul>
  
  <p>I checked and my xml files are all there.  Maybe there's a syntax error or missing linked resource, but i can't see it.  I understand the HierarchyViewer would be a useful tool to debug the UI, but i can't get it working.</p>
  
  <ul>
  <li>the id passed into FragmentTransaction.add must be a child of the layout specified in setContentView.</li>
  </ul>
  
  <p>my FragmentActivity's onCreate
          @Override
          public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_fragments_main);</p>
  
  <p>my Fragment's onCreateView</p>
  
  <pre><code>@Override 
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      Log.i("StreamingActivity","onCreateView");      
      View view = inflater.inflate(R.layout.main, container, false);
  </code></pre>
  
  <p>I presume that the LayoutManager passes the correct value for container, i.e., the one set in FragmentActivity's setContentView().  But we never make it there anyway.  The error in the logCat occurs before we enter onCreateView().</p>
  
  <p>The only thing i can think of atm is that the startupActivity (which is closed third party) called after setContentView and before StreamingActivity sets the content view to something besides R.layout.activity_fragments_main which is not a parent of my fragment's view.</p>
  
  <p>The problem seems to stem from the fact that while Activity has setContentView which can be called whenever, Fragment only has onCreateView() which gets called after fragment transactions that start the fragment.</p>
  
  <p>Why and what is trying to access the fragment's view before onCreateView() is called?</p>
  
  <p>darKoram</p>