title: Location Listener in Android gives java.lang.IllegalArgumentException: Invalid listener : null
body: <p>Hey While I am running the application it gives a error java.lang.IllegalArgumentException: Invalid listener : null , that tells that listener is null. I am beginner so please anyone help to fix this problem. I got error in this line : locationManager.requestLocationUpdates(provider, 2000, 0, locationListener);
  //My sample code is here:</p>
  
  <pre><code>    public class MainActivity extends MapActivity  {
      GoogleMap map;
      MapController mapController;
      LocationListener locationListener;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          MapView myMapView = (MapView)findViewById(R.id.mapview);
          mapController = myMapView.getController();
          myMapView.setSatellite(true);
          myMapView.setStreetView(true);
          myMapView.displayZoomControls(false);
          mapController.setZoom(16);
  
          LocationManager locationManager;
          String context = Context.LOCATION_SERVICE;
          locationManager = (LocationManager)getSystemService(context);
  
          Criteria criteria = new Criteria();
          criteria.setAccuracy(Criteria.ACCURACY_FINE);
          criteria.setAltitudeRequired(false);
          criteria.setBearingRequired(false);
          criteria.setCostAllowed(true);
          criteria.setPowerRequirement(Criteria.POWER_LOW);
  
          String provider = locationManager.getBestProvider(criteria, true);
           Location location = locationManager.getLastKnownLocation(provider);
  
           updateWithNewLocation(location);
         locationManager.requestLocationUpdates(provider, 2000, 0, locationListener);
  
      }
      private void updateWithNewLocation(Location location) {
  
          // TODO Auto-generated method stub
          String latLongString;
          TextView myLocationText;
          myLocationText = (TextView)findViewById(R.id.maptextview);
  
          String addressString = "No Address Found";
  
          if(location != null)
          {
              Double geoLat = location.getLatitude()*1E6;
              Double geoLng = location.getLongitude()*1E6;
  
              GeoPoint point = new GeoPoint(geoLat.intValue(),geoLng.intValue());
  
  
              mapController.animateTo(point);
              Double lat = location.getLatitude();
              Double lng = location.getLongitude();
  
              latLongString ="Lat : "+lat+ "\n Long : "+lng;
  
              Double latitude = location.getLatitude();
              Double longitude = location.getLongitude();
  
              Geocoder gc = new Geocoder(this, Locale.getDefault());
  
              try
              {
                  List&lt;Address&gt; addresses = gc.getFromLocation(latitude, longitude, 1);
                  StringBuilder sb = new StringBuilder();
                  if(addresses.size() &gt; 0)
                  {
                      Address address = addresses.get(0);
                      for(int i=0; i &lt; address.getMaxAddressLineIndex(); i++)
                          sb.append(address.getAddressLine(i)).append("\n");
                      sb.append(address.getLocality()).append("\n");
                      sb.append(address.getPostalCode()).append("\n");
                      sb.append(address.getCountryName()).append("\n");
  
                  }
                  addressString = sb.toString();
              }
              catch(IOException e){ }
          }
          else {
              latLongString = "No Location Found";
          }
          myLocationText.setText("your current position : "+latLongString+"\n"+addressString);        
      }
  
      @Override
      protected boolean isRouteDisplayed() {
          // TODO Auto-generated method stub
          return false;
      }
  }
  </code></pre>