System.NullReferenceException:<超时超过=“ =” getting =“” exception =“” details =“”>-需要一些线索

时间:2019-05-06 13:19:31

标签: c# xamarin.forms

您好,我是Xamarin和C#的新手。我有一个尝试保存联系信息的简单代码。当我在模拟器上运行它时,出现以下错误:System.NullReferenceException:

我的MainPage.xaml.cs看起来像这样:

namespace Contact
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        void SaveButton_Clicked(object sender, EventArgs e)
        {
            Contacts contact = new Contacts()
            {
                Name = nameEntry.Text,
                LastName = lastnameEntry.Text,
                Email = emailEntry.Text,
                PhoneNumber = phoneEntry.Text,
                Address = addressEntry.Text

            };

            using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
            {
                conn.CreateTable<Contacts>();
                int rowsAdded = conn.Insert(contact);
            }
        }
    }
}

Contacts类是在单独的文件Contact.cs中定义的

using System;
using SQLite;

namespace Contact.Classes
{
    public class Contacts
    {
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }
        public String Name { get; set; }
        public String LastName { get; set; }
        public String Email { get; set; }
        public String PhoneNumber { get; set; }
        public String Address { get; set; }

    }
}

0 个答案:

没有答案