3

When I call an Android ContentProvider I get the following exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{de.harm.android.couchone/de.harm.android.couchone.CouchContactClient}: java.lang.IllegalArgumentException: Unknown URL content://de.harm.android.couchone.provider/test2

These are the projects:

Android uses the so-called ContentResolver to communicate with ContentProvider which in turn handles the persistence functionality - accessing the database.

The ContentProvider registers itself with a unique Uri. The ContentResolver calls the ContentProvider with this Uri and passes additional data, like a SQL query string and/or data to be saved.

In the CouchOneProvider/AndroidManifest.xml I have the following:

<provider android:authorities="de.harm.android.couchone.provider"
   android:name=".Provider" />

The Provider uses

static {
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    uriMatcher.addURI(PROVIDER_NAME, DB_Name, URI_COLLECTION);
    uriMatcher.addURI(PROVIDER_NAME, DB_Name + "/#", URI_ENTITY);
}

and

public static boolean isCollectionUri(Uri uri) {
    return uriMatcher.match(uri) == URI_COLLECTION;
}

to process the CONTENT_URI used by the ContentResolver to call the ContentProvider:

  • Am I missing permissions in any of both AndroidManifest.xml?
  • Am I defining the authority in AndroidManifest.xml wrongly?
  • Is the CONTENT_URI wrong?

Update:

I have additional information:

Logcat says:

Failed to find provider info for de.harm.android.couchone.provider

This should be the starting point. But so far I couldn't find any solution.

The fully qualified classname of the ContentProvider implementation is:

de.harm.android.couchone.Provider

In AndroidManifext.xml exactly this is specified as authority, except for the name being to lower case, but this should be fine.

The package name is defined previously in the xml file, so ".Provider" should be ok, too.

As to be seen in the exception, the client calls:

content://de.harm.android.couchone.provider/test2

Logcats answer is:

Failed to find provider info for de.harm.android.couchone.provider

I don't see what's missing, perhaps it's Eclipse or emulator problem?

I install the provider as "run project as Android application".

rekire
  • 47,260
  • 30
  • 167
  • 264
Hans
  • 31
  • 1
  • 2

2 Answers2

3

I have resolved this problem:

Both projects had the same package structure. I changed de.harm.android.couchone to de.harm.android.couchone.provider and de.harm.android.couchone.client.

rekire
  • 47,260
  • 30
  • 167
  • 264
user540327
  • 31
  • 2
0

I think this link is related to question topic. How to implement a custom content-provider.

burtek
  • 2,576
  • 7
  • 29
  • 37
SohailAziz
  • 8,034
  • 6
  • 41
  • 43