title: Ask the user to enable GPS or network provider...illegalargumentexception provider==null
body: <p>I'm trying to write a code that make the application asking  user to enable providers to locate it...I tried this code but it crashes when providers are disabled :</p>
  
  <pre><code>   SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
  
                  // Getting GoogleMap object from the fragment
                  map = fm.getMap();
  
                  // Enabling MyLocation Layer of Google Map
                  map.setMyLocationEnabled(true); 
  
                   // Getting LocationManager object from System Service LOCATION_SERVICE
                  if(locationManager==null)
                  locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
                  try{
                      gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
                      }catch(Exception ex){}
                      try{
                      network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
                      }catch(Exception ex){}
  
                     if(!gps_enabled &amp;&amp; !network_enabled){
                         Builder  dialog = new AlertDialog.Builder(this);
                         dialog.setMessage("Activez l'un des ressources de localisation" );
                          dialog.setPositiveButton("Setting", new DialogInterface.OnClickListener() {
  
  
                              @Override
                              public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                                  // TODO Auto-generated method stub
                                  startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 100);
                              }
                          });
                          dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  
                              @Override
                              public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                                  // TODO Auto-generated method stub
  
                              }
                          });
                          dialog.show();
  
                     }
                  // Creating a criteria object to retrieve provider
                  Criteria criteria = new Criteria();
  
                  // Getting the name of the best provider
                   provider = locationManager.getBestProvider(criteria, true);
  
                  // Getting Current Location
                  Location location = locationManager.getLastKnownLocation(provider);
  
                  if(location!=null){
                          onLocationChanged(location);
                  }
  
                  locationManager.requestLocationUpdates(provider, 20000, 0, this);
  
              }
  
          }
  </code></pre>
  
  <p>and this is logcat</p>
  
  <pre><code>08-06 02:59:16.609: E/AndroidRuntime(20881): FATAL EXCEPTION: main
  08-06 02:59:16.609: E/AndroidRuntime(20881): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.find/com.example.MapActivity}: java.lang.IllegalArgumentException: provider==null
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1808)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:737)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.widget.TabHost.setCurrentTab(TabHost.java:401)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:154)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:540)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.view.View.performClick(View.java:3534)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.view.View$PerformClick.run(View.java:14263)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.os.Handler.handleCallback(Handler.java:605)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.os.Handler.dispatchMessage(Handler.java:92)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.os.Looper.loop(Looper.java:137)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.ActivityThread.main(ActivityThread.java:4441)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at java.lang.reflect.Method.invoke(Method.java:511)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at dalvik.system.NativeStart.main(Native Method)
  08-06 02:59:16.609: E/AndroidRuntime(20881): Caused by: java.lang.IllegalArgumentException: provider==null
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1028)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at com.example.findyourmosque.MapActivity.onCreate(MapActivity.java:117)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.Activity.performCreate(Activity.java:4465)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
  08-06 02:59:16.609: E/AndroidRuntime(20881):    ... 18 more
  </code></pre>
  
  <p>can someone help me? thanks in advance.</p>