title: MapView google maps NullPointerException?
body: <p>I'm trying create a <strong>How to get</strong> using MapView. I created a Fragment and a XML to use that. The problem is when I try open the MapView throws a  <strong>NullPointerException</strong> but I can't undertand why. </p>
  
  <p>How could I solve it ?</p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;com.google.android.gms.maps.MapView
          android:id="@+id/mapView"
          android:layout_width="match_parent"
          android:layout_height="160dp"
          android:layout_marginRight="10dp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>The Fragment</strong></p>
  
  <pre><code>public class FormComoChegarEmpresa extends Fragment{
      MapView mapView;
      private GoogleMap googleMap;
      private final String TAG = getClass().getSimpleName() + "-&gt;";
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          ((CustomDrawerLayout)getActivity()).getSupportActionBar().hide();
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.como_chegar_empresa, container, false);
          mapView = (MapView)view.findViewById(R.id.mapView);
  
  
          return  view;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          setMapView();
      }
  
      private void setMapView() {
          try {
              MapsInitializer.initialize(getActivity().getApplicationContext());
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          googleMap = mapView.getMap();
          // latitude and longitude
          double latitude = 17.385044;
          double longitude = 78.486671;
  
          // create marker
          MarkerOptions marker = new MarkerOptions().position(
                  new LatLng(latitude, longitude)).title("Hello Maps");
  
          // Changing marker icon
          marker.icon(BitmapDescriptorFactory
                  .defaultMarker(BitmapDescriptorFactory.HUE_ROSE));
  
          // adding marker
          googleMap.addMarker(marker);
          CameraPosition cameraPosition = new CameraPosition.Builder()
                  .target(new LatLng(17.385044, 78.486671)).zoom(12).build();
          googleMap.animateCamera(CameraUpdateFactory
                  .newCameraPosition(cameraPosition));
  
          // Perform any camera updates here
      }    
  
  }
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <pre><code>java.lang.NullPointerException
              at br.com.package.myapp.frags.FormComoChegarEmpresa.setMapView(FormComoChegarEmpresa.java:80)
              at br.com.package.myapp.frags.FormComoChegarEmpresa.onActivityCreated(FormComoChegarEmpresa.java:56)
              at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1794)
              at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:967)
              at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
              at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
              at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
              at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
              at android.os.Handler.handleCallback(Handler.java:733)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:157)
              at android.app.ActivityThread.main(ActivityThread.java:5356)
              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:1265)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>