C# Windows phone 8应用程序,类型为';System.NullReferenceException';在导航服务期间发生

C# Windows phone 8应用程序,类型为';System.NullReferenceException';在导航服务期间发生,c#,windows-phone-8,isolatedstorage,C#,Windows Phone 8,Isolatedstorage,我遇到一个问题,windows phone 8应用程序在this.NavigationService.Navigate(新Uri(“/Dashboard.xaml”,UriKind.Relative))上崩溃;当它试图导航到新页面时。应用程序应该加载到下面的欢迎页面,检查是否是用户第一次打开应用程序,如果是,则应保持在该页面上,直到用户单击按钮继续。但如果这不是用户第一次打开应用程序,它应该检查,然后直接进入仪表板。但是错误就在这里,它不想导航,因为它显示了下面的错误。我已经浏览了关于这个错误消

我遇到一个问题,windows phone 8应用程序在this.NavigationService.Navigate(新Uri(“/Dashboard.xaml”,UriKind.Relative))上崩溃;当它试图导航到新页面时。应用程序应该加载到下面的欢迎页面,检查是否是用户第一次打开应用程序,如果是,则应保持在该页面上,直到用户单击按钮继续。但如果这不是用户第一次打开应用程序,它应该检查,然后直接进入仪表板。但是错误就在这里,它不想导航,因为它显示了下面的错误。我已经浏览了关于这个错误消息的所有其他帖子,但是没有任何答案可以帮助解决当前的问题

这是给出的错误消息

Good Morning Dashboard.DLL中发生“System.NullReferenceException”类型的异常,但未在用户代码中处理。其他信息:对象引用未设置为对象的实例。如果存在此异常的处理程序,则程序可以安全地继续

这是密码

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Good_Morning_Dashboard.Resources;
using System.IO.IsolatedStorage;

namespace Good_Morning_Dashboard
{
    public partial class MainPage : PhoneApplicationPage
    {
        public bool trueOrFalse;
        public string result;

        public MainPage()
        {
            InitializeComponent();

            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            if (!settings.Contains("DataKey"))
            {
                settings.Add("DataKey", "First Time");

            }
            else
            {
                settings["DataKey"] = "Not First Time";
                this.NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
            }

            settings.Save();



        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
        }
    }
}

先谢谢你!:)

使用导航服务的位置有限制。我相信您不能在页面构造函数中使用它,因为到那时它还没有准备好。您可能希望将其放在
页面中。改为在导航到
覆盖时:

    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        if (!settings.Contains("DataKey"))
        {
            settings.Add("DataKey", "First Time");

        }
        else
        {
            settings["DataKey"] = "Not First Time";
            this.NavigationService.Navigate(new Uri("/Dashboard.xaml", UriKind.Relative));
        }

        settings.Save();
    }