DummyLocationProvider issue
<p>I'm trying to get the latitude and longitude and below is class which does that...
But i get android runtime exception at </p>

<p>Location l = locMgr.getLastKnownLocation(bestProvider);</p>

<p>and at longt = Double.toString(loc.getLongitude());</p>

<p>Also provider is always shown as DummyLocationProvider even on the phone</p>

<pre><code>public class Util implements LocationListener {

public static LocationManager locMgr;
private static List&lt;String&gt; providers;
private static String bestProvider;
private Context context;
public static String lat;
public static String longt;

public Util(Context context) {  
    this.context = context;     
    if(locMgr == null)          //Get LocationManager
        locMgr = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
}

public void getLocations() {
    //List All providers
    providers = locMgr.getAllProviders();

    //Get criteria
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);

    //Get best provider
    bestProvider = locMgr.getBestProvider(criteria, false);       
    printProvider(bestProvider);

    //Get Last known location
    Location l = locMgr.getLastKnownLocation(bestProvider);
     if(l==null)
        System.out.println("im null");
    printLocation(l);

}

private void printLocation(Location loc) {

    if(loc == null) {       //means there is no recent location
            getNewLocation();

    }else
            lat = Double.toString(loc.getLatitude());
            longt = Double.toString(loc.getLongitude()); 
            System.out.println("cached " + lat + " " + longt);

}


private void printProvider(String provider) {
    System.out.println(provider);
    LocationProvider info = locMgr.getProvider(provider);
    System.out.println("provider= " + info.toString() + "\n\n");
}


private boolean getNewLocation() {

    if(locMgr.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {                //This is executed since it can get locations faster than gps (is executed only if use wireless networks for locations is selected)

            locMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
            return true;

    }else if(locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER)) {      //This is exceuted if n/w locations is turned off &amp;  gps is turned on

            locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
            return true;
    }else {                 //executed when gps &amp; location by network is turned off..             
        return false;
    }

}
</code></pre>
