title: Cannot resolve method getMap()
body: <p>I am trying to get a map fragment working within my application and I continue to get an error when trying to get my GoogleMap object.</p>
  
  <blockquote>
    <p>FragmentWithMap.java</p>
  </blockquote>
  
  <pre><code>import android.Manifest;
  import android.app.Activity;
  import android.content.pm.PackageManager;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.app.Fragment;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  import com.google.android.gms.maps.CameraUpdate;
  import com.google.android.gms.maps.CameraUpdateFactory;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.SupportMapFragment;
  import com.google.android.gms.maps.model.BitmapDescriptorFactory;
  import com.google.android.gms.maps.model.LatLng;
  import com.google.android.gms.maps.model.Marker;
  import com.google.android.gms.maps.model.MarkerOptions;
  
  
  
  public class FragmentWithMap extends android.support.v4.app.Fragment {
      private OnFragmentInteractionListener mListener;
      private static final double LAT = 32.084;
      private static final double LON = 34.8878;
      Place place;
      private GoogleMap mMap;
      private View view;
      private Marker marker;
      int userIcon = FragmentWithDetails.userIcon;
  
      public static FragmentWithMap newInstance(Place place) {
          Bundle args = new Bundle();
          if (place != null) {
              args.putInt("id", place.getId());
              args.putString("name", place.getName());
              args.putString("address", place.getAddress());
              args.putFloat("lat", place.getLat());
              args.putFloat("lng", place.getLng());
          }
          FragmentWithMap fragment = new FragmentWithMap();
          fragment.setArguments(args);
          return fragment;
      }
  
      public FragmentWithMap() {
          //empty public constructor
      }
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (getArguments() != null &amp;&amp; getArguments().getString("name") != null) {
              place = new Place(getArguments().getInt("id"), getArguments().getString("name"),
                      getArguments().getString("address"), getArguments().getFloat("lat"),
                      getArguments().getFloat("lng"));
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          if (view == null) {
              view = inflater.inflate(R.layout.fragment_fragment_with_map, container, false);
          }
          setUpMapIfNeeded();
          return view;
      }
  
      @Override
      public void onDestroyView() {
          super.onDestroyView();
          android.support.v4.app.Fragment f = getFragmentManager()
                  .findFragmentById(R.id.fragmnet_container_map);
          if (f != null) {
              try {
                  getFragmentManager().beginTransaction().remove(f).commit();
              } catch (IllegalStateException ise) {
                  Log.d("FragmentWithMap", "Already closed");
              }
          }
  
          ViewGroup parentViewGroup = (ViewGroup) view.getParent();
          if (parentViewGroup != null) {
              parentViewGroup.removeAllViews();
          }
      }
  
      public void onButtonPressed(Uri uri) {
          if (mListener != null) {
              mListener.onFragmentInteraction(uri);
          }
      }
  
      @Override
      public void onAttach(Activity activity) {
          super.onAttach(activity);
          try {
              mListener = (OnFragmentInteractionListener) activity;
          } catch (ClassCastException e) {
              throw new ClassCastException(activity.toString()
                      + " must implement OnFragmentInteractionListener");
          }
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
          mListener = null;
      }
  
      public void showPlace(Place place) {
          setPlace(place);
          setUpMap();
      }
  
      public void setPlace(Place place) {
          this.place = place;
      }
  
  
      public interface OnFragmentInteractionListener {
          public void onFragmentInteraction(Uri uri);
      }
  
      private void setUpMapIfNeeded() {
          // Do a null check
          if (mMap == null) {
              // Try to obtain the map from the SupportMapFragment.
  
  
              Fragment mmm = getChildFragmentManager().findFragmentById(R.id.fragment_map2);
              mMap = ((SupportMapFragment) mmm).getMap();
  
              // Check if we were successful
              if (mMap != null) {
                  setUpMap();
              }
          }
      }
  
      private void setUpMap() {
          double lat = LAT;
          double lng = LON;
          String name = "You are here";
          if (place != null) {
              lat = place.getLat();
              lng = place.getLng();
              name = place.getName();
          }
          if (marker != null) {
              marker.remove();
          }
          LatLng position = new LatLng(lat, lng);
          MarkerOptions markerOptions = new MarkerOptions().
                  position(position).
                  title(name).
                  icon(BitmapDescriptorFactory.fromResource(userIcon)).
                  snippet("Your last recorded location");
  
          marker = mMap.addMarker(markerOptions);
          if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              return;
          }
          mMap.setMyLocationEnabled(true);
          CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, 15);
          mMap.animateCamera(cameraUpdate);
      }
  
  }
  </code></pre>
  
  <p>And here's the XML</p>
  
  <blockquote>
    <p>fragment_with_map.xml</p>
  </blockquote>
  
  <pre><code>&lt;fragment 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:id="@+id/fragment_map2"
      tools:context="com.example.eldad.myplacesapp.FragmentWithMap"
      android:name="com.google.android.gms.maps.SupportMapFragment"
      /&gt;
  </code></pre>
  
  <p>I copied the code from a different app, where the method getMap() is merely deprecated, so I doubt the problem is in the code itself. I have no issue with it being deprecated, and I prefer not to use the getMapAsync() if I don't have to. But here for some reason I recieve the error </p>
  
  <blockquote>
    <p>"Cannot resolve method 'getMap()'"</p>
  </blockquote>
  
  <p>. I also recieve an error </p>
  
  <blockquote>
    <p>"Error:Execution failed for task ':app:compileDebugJavaWithJavac'.</p>
    
    <blockquote>
      <p>Compilation failed; see the compiler error output for details."</p>
    </blockquote>
  </blockquote>
  
  <p>Though I can't be sure if it's connected to this issue.</p>