akubabas
akubabas

Reputation: 473

Caused by: java.lang.IllegalArgumentException: provider==null

i have apps to access GPS... but if my GPS not enabled my apps have force close... this is my code,

private void cekGPS() {
    // TODO Auto-generated method stub
    LocationManager locationManager;
    locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 1.0F, this);
    boolean isGPS=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    //pastike sek murup po rak GPS ,e
        if(isGPS==false){
            Toast.makeText(this, "GPS gak aktip", Toast.LENGTH_LONG);
            System.out.println("GPSmati");
            startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);

        } else {
            //lha nek wes pasti murup langsung di cek last know trus lebok2.e 

            System.out.println("GPSmurup");
            Toast.makeText(this, "GPS Aktif", Toast.LENGTH_LONG).show();

        }
}

but I have error:

03-22 11:16:14.525: ERROR/AndroidRuntime(5426): Caused by: java.lang.IllegalArgumentException: provider==null

Can anybody help me? Thank you.

Upvotes: 1

Views: 2353

Answers (1)

Kumar Bibek
Kumar Bibek

Reputation: 9117

Do you have persmissions for your app to access GPS? From the log, it seems, either the permission is not there, or the device/emulator doesn't recognize a GPS sensor. And thus, the provider is null.

On which line exactly are you getting this exception? That would help in getting to the root of it.

Upvotes: 1

Related Questions