title: How to add android Toolbar to an Activity that has a Fragment
body: <p>I created a new Project in Android Studio - a Blank Activity with Fragment. It created the following files</p>
  
  <ul>
  <li>MainActivty.java MainActivityFragment.java activity_main.xml
  fragment_main.xxml</li>
  </ul>
  
  <p>Now I wanted to add a Toolbar so I created a app_bar.xml as follows</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:local="http://schemas.android.com/apk/res-auto"
      android:id="@+id/app_bar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:minHeight="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /&gt;
  </code></pre>
  
  <p>I modified the MainActivity.java as below</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private Toolbar toolbar;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          toolbar = (Toolbar) findViewById(R.id.app_bar);
          this.setSupportActionBar(toolbar);
      }
  </code></pre>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/fragment"
      android:name="com.lalapetstudios.udacityprojects.spotifystreamer.MainActivityFragment"
      tools:layout="@layout/fragment_main" android:layout_width="match_parent"
      android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>fragment.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" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivityFragment"&gt;
  
      &lt;TextView android:text="@string/hello_world" android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>When I run this. I get the following exception</p>
  
  <blockquote>
    <p>Caused by: java.lang.NullPointerException: Attempt to invoke virtual
    method 'java.lang.CharSequence
    android.support.v7.widget.Toolbar.getTitle()' on a null object
    reference</p>
  </blockquote>
  
  <p>So I modified my activity_main.xml as follows</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" /&gt;
  
  &lt;fragment
          android:id="@+id/fragment"
          android:name="com.lalapetstudios.udacityprojects.spotifystreamer.MainActivityFragment"
          tools:layout="@layout/fragment_main" android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Also modified the app_bar.xml as follows (removed the android:id parameter)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:local="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:minHeight="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /&gt;
  </code></pre>
  
  <p>Now the App runs. Im able to see the Toolbar. However the Fragment is hidden behind the tool bar. The HelloWorld is behind the Toolbar. How do I fix it. Thank you.</p>