title: NullPointerException at mapFragment.getMapAsync
body: <p>After going through SO questions relating to my title, I couldn't find a solution to the problem. I am having a <code>NullPointerException</code> at <code>mapFragment.getMapAsync</code>. Below is my <code>MapActivity</code> code.</p>
  
  <pre><code>package com.example.jerofad.mylocation;
  import android.app.FragmentManager;
  import android.support.v4.app.FragmentActivity;
  import android.os.Bundle;
  import com.google.android.gms.maps.CameraUpdateFactory;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.OnMapReadyCallback;
  import com.google.android.gms.maps.SupportMapFragment;
  import com.google.android.gms.maps.model.LatLng;
  import com.google.android.gms.maps.model.MarkerOptions;
  public class MapsActivity extends FragmentActivity implements  OnMapReadyCallback {
      private GoogleMap mMap;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_maps);
          // Obtain the SupportMapFragment and get notified when the map is ready to be used.
          SupportMapFragment mapFragment = (SupportMapFragment) this.getSupportFragmentManager()
                  .findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
      }
  
      @Override
      public void onMapReady(GoogleMap googleMap) {
          mMap = googleMap;
          // Add a marker in Sydney and move the camera
          LatLng sydney = new LatLng(-34, 151);
          mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
          mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
          mMap.getUiSettings().setZoomControlsEnabled(true);
      }
  }
  </code></pre>
  
  <p>I am using <code>google play service 8.4.0</code>. My Android Manifest is given below.</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.example.jerofad.mylocation"&gt;
  
  &lt;!--
       The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
       Google Maps Android API v2, but you must specify either coarse or fine
       location permissions for the 'MyLocation' functionality. 
  --&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
      android:maxSdkVersion="22"/&gt;
  &lt;permission
      android:name="com.example.jerofad.mylocation.permission.MAPS_RECEIVE"
      android:protectionLevel="signature" /&gt;
  &lt;uses-permission android:name="com.example.jerofad.mylocation.permission.MAPS_RECEIVE" /&gt;
  &lt;uses-permission
      android:name="android.permission.READ_EXTERNAL_STORAGE"
      android:maxSdkVersion="22" /&gt;
  &lt;uses-feature
      android:glEsVersion="0x00020000"
      android:required="true" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/mylocation"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;        
      &lt;meta-data
          android:name="com.google.android.geo.API_KEY"
          android:value="@string/google_maps_key" /&gt;
      &lt;meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" /&gt;
  
      &lt;activity
          android:name=".MapsActivity"
          android:label="@string/title_activity_maps"&gt;
  
      &lt;/activity&gt;
      &lt;activity
          android:name=".LauncherActivity"
          android:label="@string/title_activity_launcher"
          android:theme="@style/AppTheme.NoActionBar"&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;
  </code></pre>
  
  <p></p>
  
  <p>How can I fix the error at <code>mapFragment.getMapAsync(this)</code>. Thanks in advance. Here is the crash Log.</p>
  
  <pre><code>04-25 11:11:49.079 31448-31448/com.example.jerofad.mylocation 
  E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.jerofad.mylocation, PID: 31448
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jerofad.mylocation/com.example.jerofad.mylocation.MapsActivity}: java.lang.NullPointerException
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
     at android.app.ActivityThread.access$800(ActivityThread.java:151)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
     at android.os.Handler.dispatchMessage(Handler.java:110)
     at android.os.Looper.loop(Looper.java:193)
     at android.app.ActivityThread.main(ActivityThread.java:5299)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:515)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
     at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
     at com.example.jerofad.mylocation.MapsActivity.onCreate(MapsActivity.java:24)
     at android.app.Activity.performCreate(Activity.java:5423)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
     at android.os.Handler.dispatchMessage(Handler.java:110) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5299) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:515) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) 
     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Here is the activity_maps.xml.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;fragment xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/map"
      class ="com.google.android.gms.maps.MapFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.example.jerofad.mylocation.MapsActivity" /&gt;
  </code></pre>