title: Google map called inside a fragment returns null
body: <p>I am trying to put Map inside a fragment. 
  I am pasting the codes I am using</p>
  
  <p>XML</p>
  
  <pre><code>           &lt;fragment
              android:id="@+id/contactFrag_F_map"
              android:name="com.google.android.gms.maps.MapFragment"
              android:layout_width="match_parent"
              android:layout_height="200dp"/&gt;
  </code></pre>
  
  <p>Below is my Fragment name declared</p>
  
  <pre><code>public class ContactFragment extends MapFragment 
  </code></pre>
  
  <p>Below is how I initialised map</p>
  
  <pre><code>private void initilizeMap() {
      if (googleMap == null) {
  
          if (googleMap == null) {
              googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(
                      R.id.contactFrag_F_map)).getMap();
          }
          // check if map is created successfully or not
          if (googleMap == null) {
              Toast.makeText(getActivity(),
                      "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                      .show();
          }
      }
  }
  </code></pre>
  
  <p>And this method was called on <code>onCreateView</code></p>
  
  <p>The error is </p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.MapFragment.getMap()' on a null object reference
  </code></pre>
  
  <p>Please help to solve this issue. The issue is in below portion</p>
  
  <pre><code>if (googleMap == null) {
                  googleMap = ((MapFragment) getActivity().getFragmentManager().findFragmentById(
                          R.id.contactFrag_F_map)).getMap();
              }
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Changed the xml to </p>
  
  <pre><code>&lt;fragment
                  android:id="@+id/contactFrag_F_map" 
                  android:name="com.google.android.gms.maps.SupportMapFragment"
                  android:layout_width="match_parent"
                  android:layout_height="200dp"/&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class ContactFragment extends SupportMapFragment
  </code></pre>
  
  <p>And the initialisation </p>
  
  <pre><code>if (googleMap == null) {
                  googleMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(
                          R.id.contactFrag_F_map)).getMap();
              }
  </code></pre>
  
  <p>But again the error is </p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.SupportMapFragment.getMap()' on a null object reference
  </code></pre>
  
  <p>and it happens in the line </p>
  
  <pre><code>if (googleMap == null) {
                      googleMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(
                              R.id.contactFrag_F_map)).getMap();
                  }
  </code></pre>
  
  <p>Why would this happen??</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Yes.. the getmap is deprecated . So i tried</p>
  
  <pre><code>MapFragment mapFragment = (MapFragment) getChildFragmentManager().findFragmentById(R.id.contactFrag_F_map);
          mapFragment.getMapAsync(this);
  </code></pre>
  
  <p>and ..</p>
  
  <pre><code>public class ContactFragment extends MapFragment implements OnMapReadyCallback { 
  </code></pre>
  
  <p>and the callback ..</p>
  
  <pre><code>@Override
      public void onMapReady(GoogleMap googleMap) {
  
          theGoogleMap = googleMap;
  
          setUpMap();
      }
  </code></pre>
  
  <p>and the setUpMap method</p>
  
  <pre><code>public void setUpMap(){
  
          theGoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
          theGoogleMap.setMyLocationEnabled(true);
          theGoogleMap.setTrafficEnabled(true);
          theGoogleMap.setIndoorEnabled(true);
          theGoogleMap.setBuildingsEnabled(true);
          theGoogleMap.getUiSettings().setZoomControlsEnabled(true);
      }
  </code></pre>
  
  <p>And the error is showing in onresume()</p>
  
  <pre><code>java.lang.RuntimeException: Unable to resume activity {com.purpletab.daga/com.purpletab.daga.activities.CoreActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.e.fl.o()' on a null object reference
  </code></pre>
  
  <p>also </p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.maps.api.android.lib6.e.fl.o()' on a null object reference
  </code></pre>