如何在iOS中修复“ System.ArgumentNullException”?

时间:2019-04-05 17:12:19

标签: c# ios xamarin

我正在开发由我们大学中的另一个小组提供给我们的应用程序。我正在使用Xamarin制作一个跨平台应用程序,该应用程序是我们从去年小组中挑选的。他们在iOS方面一无所获,并且在android上运行良好。

我正在使用iOS,第一页遇到了一些问题。它有一个带您进入列表视图的按钮,但是当我按此按钮时,错误

System.ArgumentNullException has been thrown
Value cannot be null.
Parameter name: sourceFileName

出现。

我尝试查找参数名称,但是没有名为sourceFileName的文件。

这在main.cs中-

public class Application
{
    static void Main(string[] args)
    {
        class from "AppDelegate"
        UIApplication.Main(args, null, "AppDelegate");
        //This is where the error pops up ^
    }
}

这是appdelegate文件-

[Register(“ AppDelegate”)] 公共局部类AppDelegate:global :: Xamarin.Forms.Platform.iOS.FormsApplicationDelegate {

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());

    return base.FinishedLaunching(app, options);
}

}

这是按钮的代码-

private async void Button_Clicked(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new SelectCancerType());
        }

SelectCancerType-

public partial class SelectCancerType : ContentPage
    {
        private string Cancer { get; set; }
        public SelectCancerType()
        {
            NavigationPage.SetHasNavigationBar(this, false);
            InitializeComponent();
            BindingContext = new SelectCancerTypeViewMode();
        }
        private async void Button_Back_Clicked(object sender, EventArgs e)
        {
            string page = "cancer";
            // handle the tap  
            await Navigation.PushAsync(new Helps(page));
        }

        private async void Button_Next_Clicked(object sender, EventArgs e)
        {
            try
            {
                Cancer = CancerTypeList.SelectedItem.ToString();
                await Navigation.PushAsync(new Treatments(Cancer));
            }
            catch(Exception ex)
            {
                await DisplayAlert("Error", "Please select an option", "OK");
            }

        }

SelectCancerTypeViewMode的代码-

public class SelectCancerTypeViewMode :BaseViewModel
    {      
        public List<string> Cancers { get; set; }
        public SelectCancerTypeViewMode()
        {
            Cancers = App.Database.GetCancers();
        }
    }

完整Stacktrace-

System.ArgumentNullException:值不能为null。 参数名称:sourceFileName   在/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS中的System.IO.File.Copy(System.String sourceFileName,System.String destFileName,System.Boolean覆盖)[0x00003] /mcs/class/corlib/System.IO/File.cs:77   在/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS/mcs/class/中的System.IO.File.Copy(System.String sourceFileName,System.String destFileName)[0x00000] corlib / System.IO / File.cs:69   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab.iOS/FileAccessHelper.cs:27中的CanRehab.iOS.FileAccessHelper.CopyDatabaseIfNotExists(System.String dbPath)[0x00016]   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab.iOS/FileAccessHelper.cs:19中的CanRehab.iOS.FileAccessHelper.GetLocalFilePath(System.String fileName)[0x00010]   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab.iOS/FileLocation.cs:19中的CanRehab.iOS.FileLocation.GetDBLocation(System.String filePath)[0x00001]   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab/App.xaml.cs:28中的CanRehab.App.get_Database()[0x00001]   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab/ViewModels/SelectCancerTypeViewMode.cs:19中的CanRehab.ViewModels.SelectCancerTypeViewMode..ctor()[0x00008]   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab/Views/SelectCancerType.xaml.cs:23中的CanRehab.Views.SelectCancerType..ctor()[0x00017]   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab/MainPage.xaml.cs:22中的CanRehab.MainPage + d__1.MoveNext()[0x0000f]   在/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS/mcs/class/中的System.Runtime.CompilerServices.AsyncMethodBuilderCore + <> c.b__6_0(系统对象状态)[0x00000] referencesource / mscorlib / system / runtime / compilerservices / AsyncMethodBuilder.cs:1023   在/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS/Foundation/NSAction.cs:178中的Foundation.NSAsyncSynchronizationContextDispatcher.Apply()[0x00000]中   在(包装器托管到本地)UIKit.UIApplication.UIApplicationMain(int,string [],intptr,intptr)   在/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS中的UIKit.UIApplication.Main(System.String [] args,System.IntPtr主体,System.IntPtr委托)[0x00005] /UIKit/UIApplication.cs:79   在/Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.16/src/Xamarin.iOS中的UIKit.UIApplication.Main(System.String [] args,System.StringPrincipalClassName,System.String委托ClassName)[0x0002c] /UIKit/UIApplication.cs:63   在/Users/Isaac/Projects/stechr8/CanRehab.git/CanRehab/CanRehab/CanRehab.iOS/Main.cs:18

中的CanRehab.iOS.Application.Main(System.String [] args)[0x00001]

0 个答案:

没有答案