title: Error in Google Maps v2 Android
body: <p>I am using Google map V2 .
  I am getting nullpointerexception in that.</p>
  
  <p><strong>Map Activity</strong></p>
  
  <pre><code>public class Mapa extends FragmentActivity {
  
  private GoogleMap googleMap;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_mapa);     
      SetUpMapIfNeeded();
  }
  
  private void SetUpMapIfNeeded() {
      if(googleMap == null){
          googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mvMapa)).getMap();
          if(googleMap != null){
              setUpMap();
          }
      }
  }
  
  private void setUpMap() {   
  
      googleMap.setMyLocationEnabled(true);
  
      //Get LocationManager object from System Service LOCATION_SERVICE
      LocationManager locationM = (LocationManager)getSystemService(LOCATION_SERVICE);
  
      //Create a criteria object to retrieve provider
      Criteria criteria = new Criteria();
  
      //Get the name of the best provider
      String provider = locationM.getBestProvider(criteria, true);
  
      //Get Current Location
      Location miUbicacion = locationM.getLastKnownLocation(provider);
  
      //Set map type
      googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);                
  
      //Get Latitude of the current location
      double latitud = miUbicacion.getLatitude();
  
      //Get Longitude of the current location
      double longitud = miUbicacion.getLongitude();
  
      //Create a latLng object for the current location
      LatLng latLng = new LatLng(latitud, longitud);
  
      googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
  
      //Zoom in the Google Map
      googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
      googleMap.addMarker(new MarkerOptions().position(new LatLng(latitud, longitud)).title("Te encuentras aquí!"));
  }
  
  
  }
  </code></pre>
  
  <p><strong>LOGCAT</strong></p>
  
  <pre><code>05-12 14:11:02.806: E/AndroidRuntime(29687): FATAL EXCEPTION: main
  05-12 14:11:02.806: E/AndroidRuntime(29687): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.proyectosetit/com.example.proyectosetit.Mapa}: java.lang.NullPointerException
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.ActivityThread.access$600(ActivityThread.java:138)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.os.Handler.dispatchMessage(Handler.java:99)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.os.Looper.loop(Looper.java:213)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.ActivityThread.main(ActivityThread.java:4787)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at java.lang.reflect.Method.invokeNative(Native Method)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at java.lang.reflect.Method.invoke(Method.java:511)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at dalvik.system.NativeStart.main(Native Method)
  05-12 14:11:02.806: E/AndroidRuntime(29687): Caused by: java.lang.NullPointerException
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at com.example.proyectosetit.Mapa.setUpMap(Mapa.java:54)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at com.example.proyectosetit.Mapa.SetUpMapIfNeeded(Mapa.java:29)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at com.example.proyectosetit.Mapa.onCreate(Mapa.java:22)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.Activity.performCreate(Activity.java:5008)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
  05-12 14:11:02.806: E/AndroidRuntime(29687):    ... 11 more
  </code></pre>
  
  <p><strong>Error mark here</strong></p>
  
  <pre><code>Mapa.java: line 54
  
  double latitud = miUbicacion.getLatitude();
  </code></pre>
  
  <p>I'm trying to retrieve the device's location but I faced several problem.
  Please help me. Thanks
  ..</p>
  
  <p>.
  .
  .
  .</p>