Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法获取提供程序(ClassNotFoundException)Xamarin_C#_Xamarin_Visual Studio 2015_Xamarin.android_Android Database - Fatal编程技术网

C# 无法获取提供程序(ClassNotFoundException)Xamarin

C# 无法获取提供程序(ClassNotFoundException)Xamarin,c#,xamarin,visual-studio-2015,xamarin.android,android-database,C#,Xamarin,Visual Studio 2015,Xamarin.android,Android Database,我正在用Xamarin开发一个解决方案,其中至少包含4个不同的Android应用程序 我的目标是为这四个应用程序创建一个共享内容提供商,这样我就可以在一个地方拥有主数据(如果一个应用程序更新了该数据,我就可以在另一个应用程序中获得该更新版本) 在VisualStudio中,我创建了一个PCL项目,我在其中定义了内容提供者(我可以在所有应用程序中引用它并执行CRUD操作) 我的内容提供商如下所示: namespace com.cybertron.android.Provider { pub

我正在用Xamarin开发一个解决方案,其中至少包含4个不同的Android应用程序

我的目标是为这四个应用程序创建一个共享内容提供商,这样我就可以在一个地方拥有主数据(如果一个应用程序更新了该数据,我就可以在另一个应用程序中获得该更新版本)

在VisualStudio中,我创建了一个PCL项目,我在其中定义了内容提供者(我可以在所有应用程序中引用它并执行CRUD操作)

我的内容提供商如下所示:

namespace com.cybertron.android.Provider
{
    public class SectionProvider : ContentProvider
    {
        SectionDatabase sectDb;
        public const string AUTHORITY = "com.cybertron.android.Provider.SectionProvider";
        public const string SECTIONS_MIME_TYPE = ContentResolver.CursorDirBaseType + "/vnd.com.cybertron.android.sections";
        public const string SECTION_MIME_TYPE = ContentResolver.CursorItemBaseType + "/vnd.com.cybertron.android.section";
        static string BASE_PATH = "sections";
        static UriMatcher uriMatcher = BuildUriMatcher();
        public static readonly Android.Net.Uri CONTENT_URI = Android.Net.Uri.Parse("content://" + AUTHORITY + "/" + BASE_PATH);
        const int GET_ALL = 0;
        const int GET_ONE = 1;
        public static class SectionConsts
        {
            public const string SectNo = "SectNo";
            public const string KeyPos = "Key";
            public const string Date = "Date";
            public const string UnitID = "UnitID";
        }

        static UriMatcher BuildUriMatcher()
        {
            var matcher = new UriMatcher(UriMatcher.NoMatch);

            matcher.AddURI(AUTHORITY, BASE_PATH, GET_ALL); 
            matcher.AddURI(AUTHORITY, BASE_PATH + "/#", GET_ONE);
            return matcher;
        }
        public override bool OnCreate()
        {
            sectDb = new SectionDatabase(Context);
            return true;
        }        

        public override string GetType(Android.Net.Uri uri)
        {
            switch (uriMatcher.Match(uri))
            {
                case GET_ALL:
                    return SECTIONS_MIME_TYPE; // list
                case GET_ONE:
                    return SECTION_MIME_TYPE; // single item
                default:
                    throw new Java.Lang.IllegalArgumentException("Unknown Uri: " + uri);
            }
        } 
.
.
.        
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="com.cybertron.android.bluecork"
                android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="16" />
  <application android:label="com.cybertron.android.bluecork.blueapp">
    <provider
          android:name="com.cybertron.android.Provider.SectionProvider"
          android:authorities="com.cybertron.android.Provider.SectionProvider"
          android:exported="true" />
  </application>          
</manifest>
我在Xamarin应用程序项目中引用了我的项目。我没有设置
ContentProvider
属性,因为我了解到,如果两个应用程序使用同一个应用程序,则会发出
INSALL\u FAILED\u CONFLICT
错误。相反,我将其放在清单文件中,如下所示:

namespace com.cybertron.android.Provider
{
    public class SectionProvider : ContentProvider
    {
        SectionDatabase sectDb;
        public const string AUTHORITY = "com.cybertron.android.Provider.SectionProvider";
        public const string SECTIONS_MIME_TYPE = ContentResolver.CursorDirBaseType + "/vnd.com.cybertron.android.sections";
        public const string SECTION_MIME_TYPE = ContentResolver.CursorItemBaseType + "/vnd.com.cybertron.android.section";
        static string BASE_PATH = "sections";
        static UriMatcher uriMatcher = BuildUriMatcher();
        public static readonly Android.Net.Uri CONTENT_URI = Android.Net.Uri.Parse("content://" + AUTHORITY + "/" + BASE_PATH);
        const int GET_ALL = 0;
        const int GET_ONE = 1;
        public static class SectionConsts
        {
            public const string SectNo = "SectNo";
            public const string KeyPos = "Key";
            public const string Date = "Date";
            public const string UnitID = "UnitID";
        }

        static UriMatcher BuildUriMatcher()
        {
            var matcher = new UriMatcher(UriMatcher.NoMatch);

            matcher.AddURI(AUTHORITY, BASE_PATH, GET_ALL); 
            matcher.AddURI(AUTHORITY, BASE_PATH + "/#", GET_ONE);
            return matcher;
        }
        public override bool OnCreate()
        {
            sectDb = new SectionDatabase(Context);
            return true;
        }        

        public override string GetType(Android.Net.Uri uri)
        {
            switch (uriMatcher.Match(uri))
            {
                case GET_ALL:
                    return SECTIONS_MIME_TYPE; // list
                case GET_ONE:
                    return SECTION_MIME_TYPE; // single item
                default:
                    throw new Java.Lang.IllegalArgumentException("Unknown Uri: " + uri);
            }
        } 
.
.
.        
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="com.cybertron.android.bluecork"
                android:versionCode="1" android:versionName="1.0">
  <uses-sdk android:minSdkVersion="16" />
  <application android:label="com.cybertron.android.bluecork.blueapp">
    <provider
          android:name="com.cybertron.android.Provider.SectionProvider"
          android:authorities="com.cybertron.android.Provider.SectionProvider"
          android:exported="true" />
  </application>          
</manifest>

当我尝试调试这个应用程序时,我会在前面遇到一个错误(当应用程序在模拟器中启动时)

java.lang.RuntimeException:无法获取提供程序 com.cyberton.android.Provider.SectionProvider:
java.lang.ClassNotFoundException:未找到类 com.cyberton.android.Provider.SectionProvider在路径上: 路径列表

有人能告诉我为什么我会犯这个错误吗。其次,我想知道多个应用程序是否可以在Android系统上共享一个数据库


谢谢,

据我所知,您可以使用SQlite数据库并从多个应用程序访问它,只要它存储在应用程序安装目录之外。也就是说,当你的一个应用被卸载时,它不应该被删除。我不确定你在上面所做的是否相同。@Digitalsa1nt这也可能达到目的。你知道如何在我的应用程序之外创建SQLite数据库吗?我要找的是一个可以被多个应用程序访问的数据库。如何实现这一点。这里可以找到一些基本信息:实际上,您只需要确保数据库存储的路径可供其他应用程序访问,然后基本上检查/创建数据库是否存在或需要创建(这取决于应用程序的安装顺序,因为它们都需要检查数据库是否已存在于路径位置,如果不存在,则创建数据库。)谢谢@Digitalsa1nt,我已经知道如何在Xamarin中创建数据库。在Xamarin中,当我们在DBHelper的帮助下创建数据库时,它会自动将其放入包中。