Android: adding progressdialog to my current location finder crashes app. Need to find location once
<p>The location class:</p>

<pre><code>public class MyLocationListener implements LocationListener{
         private Context cnt;
         private ProgressDialog d;
    public MyLocationListener(Context cnt){
        this.cnt = cnt;

         this.d.show(cnt, "", "Finding your location...");

    }

     @Override
     public void onLocationChanged(Location loc){

     loc.getLatitude();
     loc.getLongitude();
     this.d.dismiss();
     String Text = "My current location is: " +"Latitud = " + loc.getLatitude() +"Longitud = " + loc.getLongitude();

     Toast.makeText( getApplicationContext(),Text,Toast.LENGTH_SHORT).show();
     }


     @Override

     public void onProviderDisabled(String provider) {

     Toast.makeText(getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT ).show();

     }


     @Override

     public void onProviderEnabled(String provider) {

     Toast.makeText(getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();

     }


     @Override
     public void onStatusChanged(String provider, int status, Bundle extras){


     }

     }/* End of Class MyLocationListener */
</code></pre>

<p>This is how I implement it:</p>

<pre><code>/* Use the LocationManager class to obtain GPS locations */

                LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                LocationListener mlocListener = new MyLocationListener(cnt);
                mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
</code></pre>

<p>I get a null pointer exception error when I add that progress dialog. When I take it out everything works fine.</p>

<p>Is the progress dialog conflicting with the Toast message?</p>

<p>EDIT:</p>

<p>It looks like onLocationChanged, well, changes often, so it ends up dismissing a dialog that was already dismissed.</p>

<p>Is there a way to only have the location found once?</p>
