title: Adding a fragment to main activity
body: <p>I'm following the Android Udacity Course and it's out dated so I tried to update it my self by adding a fragment manually to the main activity.
  This code builds fine but crashes when the app is started giving me a veeery long error in the android monitor.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          if(savedInstanceState == null)
          {
              getFragmentManager().beginTransaction().add(R.id.container,new PHFragment()).commit();
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class PHFragment extends Fragment
  {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState)
      {
          View rootView =  inflater.inflate(R.layout.fragment_main, container, false);
          // Inflate the layout for this fragment
          return rootView;
      }
  }
  </code></pre>
  
  <p>XML
  fragment_main.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout 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:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.athomield.mysunshine.MainActivity"
      android:touchscreenBlocksFocus="false"&gt;
  
      &lt;ListView
          android:id="@+id/listview_forecast"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
      &lt;/ListView&gt;
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.athomield.mysunshine.MainActivity"
      android:touchscreenBlocksFocus="false"&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>list_itemm_forecast.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/list_item_forecast_textview"
      android:gravity="center_vertical"
      &gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p>LOG</p>
  
  <p>06-23 11:23:02.878 3095-3095/com.example.athomield.mysunshine W/System: ClassLoader referenced unknown path: /data/app/com.example.athomield.mysunshine-1/lib/x86
  06-23 11:23:06.230 3095-3095/com.example.athomield.mysunshine W/System: ClassLoader referenced unknown path: /data/app/com.example.athomield.mysunshine-1/lib/x86
  06-23 11:23:06.408 3095-3105/com.example.athomield.mysunshine W/art: Suspending all threads took: 58.067ms
  06-23 11:23:06.417 3095-3105/com.example.athomield.mysunshine I/art: Background sticky concurrent mark sweep GC freed 13182(1591KB) AllocSpace objects, 9(208KB) LOS objects, 73% free, 991KB/3MB, paused 64.383ms total 75.476ms
  06-23 11:23:06.509 3095-3095/com.example.athomield.mysunshine W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
  06-23 11:23:06.685 3095-3101/com.example.athomield.mysunshine W/art: Suspending all threads took: 29.223ms
  06-23 11:23:06.772 3095-3095/com.example.athomield.mysunshine E/FragmentManager: No view found for id 0x7f0b0054 (com.example.athomield.mysunshine:id/container) for fragment PHFragment{ccbb2d0 #0 id=0x7f0b0054}
  06-23 11:23:06.772 3095-3095/com.example.athomield.mysunshine E/FragmentManager: Activity state:
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:   Local FragmentActivity b704817 State:
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:     mCreated=falsemResumed=false mStopped=false mReallyStopped=false
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:     mLoadersStarted=false
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:   FragmentManager misc state:
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:     mHost=android.support.v4.app.FragmentActivity$HostCallbacks@16b2c9
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:     mContainer=android.support.v4.app.FragmentActivity$HostCallbacks@16b2c9
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:     mCurState=1 mStateSaved=false mDestroyed=false
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:   View Hierarchy:
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:     com.android.internal.policy.PhoneWindow$DecorView{4998dce V.E..... ... 0,0-0,0}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:       android.widget.LinearLayout{9ea54ef V.E..... ... 0,0-0,0}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:         android.view.ViewStub{e812bfc G.E..... ... 0,0-0,0 #10203a9 android:id/action_mode_bar_stub}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:         android.widget.FrameLayout{94eb285 V.E..... ... 0,0-0,0}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:           android.support.v7.widget.ActionBarOverlayLayout{8c4b8da V.E..... ... 0,0-0,0 #7f0b0043 app:id/decor_content_parent}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:             android.support.v7.widget.ContentFrameLayout{eb1510b V.E..... ... 0,0-0,0 #1020002 android:id/content}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:               android.widget.RelativeLayout{1b30be8 V.E..... ... 0,0-0,0}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:                 android.support.v7.widget.AppCompatButton{44cf201 VFED..C. ... 0,0-0,0 #7f0b0055 app:id/button}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:                 android.support.v7.widget.AppCompatButton{44588a6 VFED..C. ... 0,0-0,0 #7f0b0056 app:id/button2}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:             android.support.v7.widget.ActionBarContainer{7a1f2e7 V.ED.... ... 0,0-0,0 #7f0b0044 app:id/action_bar_container}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:               android.support.v7.widget.Toolbar{da0fe94 V.E..... ... 0,0-0,0 #7f0b0045 app:id/action_bar}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:                 android.widget.TextView{595ad3d V.ED.... ... 0,0-0,0}
  06-23 11:23:06.773 3095-3095/com.example.athomield.mysunshine E/FragmentManager:               android.support.v7.widget.ActionBarContextView{5b18932 G.E..... ... 0,0-0,0 #7f0b0046 app:id/action_context_bar}
  06-23 11:23:06.774 3095-3095/com.example.athomield.mysunshine D/AndroidRuntime: Shutting down VM</p>
  
  <pre><code>                                                                            --------- beginning of crash
  </code></pre>
  
  <p>06-23 11:23:06.774 3095-3095/com.example.athomield.mysunshine E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: com.example.athomield.mysunshine, PID: 3095
                                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.athomield.mysunshine/com.example.athomield.mysunshine.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f0b0054 (com.example.athomield.mysunshine:id/container) for fragment PHFragment{ccbb2d0 #0 id=0x7f0b0054}
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                                   Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0b0054 (com.example.athomield.mysunshine:id/container) for fragment PHFragment{ccbb2d0 #0 id=0x7f0b0054}
                                                                                      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:965)
                                                                                      at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
                                                                                      at android.app.BackStackRecord.run(BackStackRecord.java:793)
                                                                                      at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
                                                                                      at android.app.FragmentController.execPendingActions(FragmentController.java:325)
                                                                                      at android.app.Activity.performStart(Activity.java:6252)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                      at android.os.Looper.loop(Looper.java:148) 
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) </p>