binncheol
binncheol

Reputation: 1453

Class Not Found Exception for ContentProvider

I am trying to write a Content Provider for my Xamarin.Android app.

I have my ContentProvder class (./ContentProviders/SitesProvider.cs):

namespace ContentProviders
{
    [ContentProvider(new string[] { ContentProviders.SitesProvider.AUTHORITY })]
    public class SitesProvider : ContentProvider
    {
        public const string AUTHORITY = "com.xamarin.sample.ContentProviders.SitesProvider";
        static string BASE_PATH = "TableName";
        public static readonly Uri CONTENT_URI = Uri.Parse("content://" + AUTHORITY + "/" + BASE_PATH);

        public override bool OnCreate()
        {
            return true;
        }

        ...
}

and in my AndroidManifest.xml I've added the following to my element

<provider android:name="com.xamarin.sample.ContentProviders.SitesProvider" android:authorities="com.xamarin.sample.ContentProviders.SitesProvider" android:exported="true"></provider>

When I try to run my application I'm receiving the following error message:

Java.lang.RuntimeException: 'Unable to get provider com.xamarin.sample.ContentProviders.SitesProvider: java.lang.ClassNotFoundException: Didn't find class "com.xamarin.sample.ContentProviders.SiteProvider" on path: DexPathList[[zip file "/data/app/com.xamarin.sample-STvUsF9R8PqrLEnQciN42g==/base.apk"],nativeLibraryDirectories=[/data/app/com.xamarin.sample-STvUsF9R8PqrLEnQciN42g==/lib/arm64, /data/app/com.xamarin.sample-STvUsF9R8PqrLEnQciN42g==/base.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64, /prets/lib64]]'

Upvotes: 0

Views: 562

Answers (1)

Cheesebaron
Cheesebaron

Reputation: 24470

The attribute you've put on the class you've created conflicts with the one that you add to the AndroidManifest manually. You should only do 1 of them.

So this means:

[ContentProvider(new string[] { ContentProviders.SitesProvider.AUTHORITY })]

Will automatically get added to the AndroidManifest at build time.

You can add more information to it, such as the exporting and naming you want to do with:

[ContentProvider(new string[] { ContentProviders.SitesProvider.AUTHORITY }, Exported = true, Name = "com.xamarin.sample.ContentProviders.SitesProvider")]

You can check the generated manifest in the obj/Debug/android folder at build time.

Upvotes: 1

Related Questions