title: my error in the java file where I wanted find current location
body: <p>I am new to android , I have been assigned to make some changes on a project which was previously made in <strong>eclipse</strong> and now we are using <strong>android studio</strong>.</p>
  
  <p>I have searched a lot over internet but I am not getting the solution that where I have to change in the code.</p>
  
  <p>my code below</p>
  
  <pre><code>`package com.attorneygeneral;`
  </code></pre>
  
  <p>public class GetLocation extends Activity implements LocationListener {</p>
  
  <pre><code>ImageView img_back,img_search;
  EditText search_loc;
  TextView txt_location,txt_longitude,txt_latitude;
  private GoogleMap googleMap;
  double lat,lng;
  static LatLng currentLoc;
  protected LocationManager locationManager;
  protected LocationListener locationListener;
  protected Context context;
  String provider;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.get_location);
      img_back=(ImageView) findViewById(R.id.img_back);
      img_search=(ImageView) findViewById(R.id.img_search);
      search_loc=(EditText) findViewById(R.id.search_loc);
      txt_location=(TextView) findViewById(R.id.txt_location);
      txt_latitude=(TextView) findViewById(R.id.latitude);
      txt_longitude=(TextView) findViewById(R.id.longitude);
      locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      locationManager.requestLocationUpdates(
              LocationManager.GPS_PROVIDER, 900000, 100,
              GetLocation.this);
      Criteria criteria = new Criteria();
      provider = locationManager.getBestProvider(criteria, false);
      Location location = locationManager
              .getLastKnownLocation(provider);
  
      if (location != null) {
          System.out.println("Provider " + provider
                  + " has been selected.");
          onLocationChanged(location);
      } else {
          Toast.makeText(getApplicationContext(),
                  "Location not available", Toast.LENGTH_LONG).show();
      }
  
      try 
      {
          if(googleMap==null)
          {
          googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();    
          }           
           /*Marker hardingLaw = googleMap.addMarker(new MarkerOptions().
           position(currentLoc).title("Location"));
  
           googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLoc, 15));
  
           googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);*/
      }
      catch (Exception e){
          e.printStackTrace();
      }
  
      search_loc.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              search_loc.setFocusable(true);
          }
      });
  
      img_back.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              finish();
          }
      });
  
      img_search.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              if(!TextUtils.isEmpty(search_loc.getText().toString())) {
  
              }
          }
      });
  }
  
  @Override
  public void onLocationChanged(Location location) {
      // txtLat = (TextView) findViewById(R.id.textview1);
      // txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:"
      // + location.getLongitude());
      System.out.println("Latitude Location :" + location.getLongitude()
              + "::" + location.getLatitude());
      lat = location.getLatitude();
      lng = location.getLongitude();
  
      Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
      StringBuilder builder = new StringBuilder();
      try {
          List&lt;Address&gt; address = geoCoder.getFromLocation(lat, lng, 1);
          int maxLines = address.get(0).getMaxAddressLineIndex();
          for (int i = 0; i &lt; maxLines; i++) {
              String addressStr = address.get(0).getAddressLine(i);
              builder.append(addressStr);
              builder.append(" ");
          }
  
          String finalAddress = builder.toString(); // This is the complete
                                                      // address.
          System.out.println("address :" + finalAddress);
  
          txt_latitude.setText(String.valueOf(lat));
          txt_longitude.setText(String.valueOf(lng));
          txt_location.setText(finalAddress); // This will display the final address.
          currentLoc = new LatLng(lat, lng);
          Marker hardingLaw = googleMap.addMarker(new MarkerOptions().
          position(currentLoc).title("Location"));
          //hardingLaw.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.location_pin));
  
          googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLoc, 15));
  
          // Zoom in, animating the camera.
          googleMap.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
  
      } 
      catch (IOException e) 
      {
      } 
      catch (NullPointerException e) 
      {
      }
  }
  
  @Override
  public void onProviderDisabled(String provider) {
      System.out.println("Latitude disable");
  }
  
  @Override
  public void onProviderEnabled(String provider) {
      System.out.println("Latitude enable");
  }
  
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
      System.out.println("Latitude status");
  }
  </code></pre>
  
  <p>}`</p>