title: Android: NullPointerException when using ActionBar
body: <p>I am getting an error saying that </p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{...}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity...
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference at com.myapp.contactList.MainPage.onCreate(MainPage.java:41)
  </code></pre>
  
  <p>And I looked up several stack overflow questions similar to this one and tried all the solutions but still having this issue. Below is my code:</p>
  
  <p><em>MainPage.java</em></p>
  
  <pre><code>public class MainPage extends AppCompatActivity{
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main_page);
  
      android.support.v7.app.ActionBar ab = getSupportActionBar();
      assert ab != null;
      ab.setDisplayHomeAsUpEnabled(true);  // I'M GETTING THE ERROR HERE AT THIS LINE
      ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#51c2f2")));
      ab.setDisplayUseLogoEnabled(true);
  </code></pre>
  
  <p><em>AndroidManifest.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.myapp.contactList"&gt;
  
   &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity
          android:name=".MainPage"
          android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
   &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><em>styles.xml</em></p>
  
  <pre><code>&lt;style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"&gt;
      &lt;!-- Customize your theme here. --&gt;
      &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
      &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
      &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p><em>activity_main_page.xml</em></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true"
     tools:context="com.myapp.contactList.MainPage"&gt;
  
     &lt;android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay"&gt;
     &lt;/android.support.design.widget.AppBarLayout&gt;
     &lt;include layout="@layout/content_main_page" /&gt;
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>