title: Access database with provider
body: <p>Few time ago, I started to work with databases and content providers, and I made a simple app to learn how to work with them.</p>
  
  <p>Now, I'm developing another app that has almost the same functionality that the one I did. I'm trying to implement the same code adapted for the new app, but I'm getting one error that I'm not able to find why is happening.</p>
  
  <p>This is LogCat's output:</p>
  
  <pre><code>02-11 10:45:59.014: E/ActivityThread(22665): Failed to find provider info for com.final.reversegeocoding
  02-11 10:45:59.024: E/AndroidRuntime(22665): FATAL EXCEPTION: main
  02-11 10:45:59.024: E/AndroidRuntime(22665): java.lang.IllegalArgumentException: Unknown URL content://com.final.reversegeocoding/places
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.content.ContentResolver.insert(ContentResolver.java:913)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at com.final.reversegeocoding.GeocodingActivity.insertPlaces(GeocodingActivity.java:427)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at com.final.reversegeocoding.GeocodingActivity.access$27(GeocodingActivity.java:416)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at com.final.reversegeocoding.GeocodingActivity$6.onClick(GeocodingActivity.java:288)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.view.View.performClick(View.java:4475)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.view.View$PerformClick.run(View.java:18786)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.os.Handler.handleCallback(Handler.java:730)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.os.Handler.dispatchMessage(Handler.java:92)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.os.Looper.loop(Looper.java:137)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at android.app.ActivityThread.main(ActivityThread.java:5419)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at java.lang.reflect.Method.invokeNative(Native Method)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at java.lang.reflect.Method.invoke(Method.java:525)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
  02-11 10:45:59.024: E/AndroidRuntime(22665):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>This is the road that the app follows to save values in the database:</p>
  
  <p><strong>MainActivity (GeocodingActivity)</strong></p>
  
  <pre><code>private void insertPlaces(String number, String street, String city, String country1, String country2, String lat, String lng){
          ContentValues newValues = new ContentValues();
          newValues.put(Places.NUMBER, number);
          newValues.put(Places.STREET, street);
          newValues.put(Places.CITY, city);
          newValues.put(Places.COUNTRY1, country1);
          newValues.put(Places.COUNTRY2, country2);
          newValues.put(Places.LAT, lat);
          newValues.put(Places.LNG, lng);
  
          getContentResolver().insert(PlacesProvider.CONTENT_URI, newValues);
  }
  </code></pre>
  
  <p><strong>ContentProvider (PlacesProvider)</strong></p>
  
  <pre><code>public class PlacesProvider extends ContentProvider {
  
      /*CONTENT_URI*/
      private static final String AUTHORITY = "com.final.reversegeocoding";
      public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/places");
  
      private PlacesDatabaseHelper mDbHelper;
      private SQLiteDatabase database;
  
      /**UriMatcher*/
      private static final int URI_PLACES = 1;
      private static final int URI_PLACE_ITEM = 2;
  
      private static final UriMatcher mUriMatcher;
      static {
          mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
          mUriMatcher.addURI(AUTHORITY, "places", URI_PLACES);
          mUriMatcher.addURI(AUTHORITY, "places/#", URI_PLACE_ITEM);
      }
  
  
      public class Places implements BaseColumns {
  
          public static final String NUMBER= "number";
          public static final String STREET= "street";
          public static final String CITY= "city";
          public static final String COUNTRY1= "country1";
          public static final String COUNTRY2= "pacountry2s";
          public static final String LAT = "latitude";
          public static final String LNG = "longitude";
      }
  
  
      @Override
      public boolean onCreate() {
          mDbHelper = new PlacesDatabaseHelper(getContext());
          return true;
      }
  
      @Override
      public Uri insert(Uri uri, ContentValues values) {
  
          database = mDbHelper.getWritableDatabase();
          long id = database.insert(PlacesDatabaseHelper.TABLE_NAME, null, values);
          Uri result = null;
  
          if (id &gt;= 0){
              result = ContentUris.withAppendedId(CONTENT_URI, id);
              getContext().getContentResolver().notifyChange(uri, null);
          }
          return result;
      }
  </code></pre>