title: error handling in android. exception Caused by: java.lang.IllegalArgumentException: provider=gps
body: <p>I've received an error report for one of my apps.</p>
  
  <p>I'm pretty much a beginner in android development, and don't quite understand where this could originate from. Where is the app code would it be best to catch all errors and for example just toast message that an error occured?</p>
  
  <p>My app basically sits and waits for GPS and/or Network location before displaying a button.
  This is the error:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to resume activity 
  {fr.mcnamara.irelandtravelguide/fr.mcnamara.irelandtravelguide.StartActivity}:
  java.lang.IllegalArgumentException: provider=gps
  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2241)
  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2256)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1789)
  at android.app.ActivityThread.access$1500(ActivityThread.java:123)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:130)
  at android.app.ActivityThread.main(ActivityThread.java:3835)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.IllegalArgumentException: provider=gps
  at android.os.Parcel.readException(Parcel.java:1326)
  at android.os.Parcel.readException(Parcel.java:1276)
  at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
  at android.location.LocationManager._requestLocationUpdates(LocationManager.java:582)
  at android.location.LocationManager.requestLocationUpdates(LocationManager.java:446)
  at fr.mcnamara.irelandtravelguide.StartActivity.onResume(StartActivity.java:112)
  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
  at android.app.Activity.performResume(Activity.java:3832)
  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2231)
  ... 12 more    
  </code></pre>
  
  <p>The code is as follows:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
  
       setContentView(R.layout.main);
  
       myButton = (Button) findViewById(R.id.GPS); 
       //myButton.setVisibility(INVISIBLE);
  
       dialog = ProgressDialog.show(this, "",  "Waiting for location...", true);
       dialog.setCancelable(true);   // 1.2
       dialog.show();         
  
       lm = (LocationManager) getSystemService(LOCATION_SERVICE);  
  }
  
  
  protected void onResume() {
      /*
       * onResume is is always called after onStart, even if the app hasn't been
       * paused
       *
       * add location listener and request updates every 1000ms or 10m
       */
      lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10f, this);
      lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 10f, this);
      super.onResume();
  }
  
  @Override
  protected void onPause() {
      /* GPS, as it turns out, consumes battery like crazy */
      lm.removeUpdates(this);
      super.onResume();
  }
  
  @Override
  public void onLocationChanged(Location location) {
      Log.v(TAG, "Location Changed");
      myButton.setVisibility( VISIBLE ); 
      noOfFixes++;
  
      /* display some of the data in the TextView */ 
       lon = location.getLongitude();
       lat = location.getLatitude();
       valsin.putDouble("lat", lat);
       valsin.putDouble("lon", lon); 
       Log.d(TAG, "set lat,lon:"+lat+","+lon);
       myButton.setVisibility(VISIBLE);
       dialog.dismiss(); 
       //txtInfo.setText("set lat,lon:"+lat+","+lon);
  }
  
  @Override
  public void onProviderDisabled(String provider) {
      /* this is called if/when the GPS is disabled in settings */
      Log.v(TAG, "Disabled");
      /* bring up the GPS settings */
      Toast.makeText(this, "GPS Disabled..", Toast.LENGTH_SHORT).show();
      //Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
      //startActivity(intent);
  }
  
  @Override
  public void onProviderEnabled(String provider) {
      Log.d(TAG, "Enabled");
      Toast.makeText(this, "GPS Enabled", Toast.LENGTH_SHORT).show();
  }
  
  @Override
  public void onStatusChanged(String provider, int status, Bundle extras) {
      /* This is called when the GPS status alters */
      switch (status) {
      case LocationProvider.OUT_OF_SERVICE:
          Log.d(TAG, "Status Changed: Out of Service");
          //Toast.makeText(this, "Status Changed: Out of Service",
          //Toast.LENGTH_SHORT).show();
          break;
      case LocationProvider.TEMPORARILY_UNAVAILABLE:
          Log.d(TAG, "Status Changed: Temporarily Unavailable");
          //Toast.makeText(this, "Status Changed: Temporarily Unavailable",
          //Toast.LENGTH_SHORT).show();
          break;
      case LocationProvider.AVAILABLE:
          Log.d(TAG, "Status Changed: Available");
          //Toast.makeText(this, "Status Changed: Available",
          //Toast.LENGTH_SHORT).show();
          break;
      }
  }
  
  @Override
  protected void onStop() {
      //finish();
      super.onStop();
  }
  </code></pre>