"对象引用未设置为对象的实例"得到错误?

时间:2014-04-20 06:35:40

标签: object reference set

我正在制作应用并收到此错误。我不知道为什么这不会导航到所需的页面。有我的代码。

  public MainPage()
    {
         InitializeComponent();
         while (appsetting.Contains("Roll_Number"))
         {
             txtBx_Login.Text = appsetting["Roll_Number"].ToString();
             Btn_Login1_Click(null,null);
         }
    }
 private void Btn_Login1_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            string id = txtBx_Login.Text;

            id = id.Substring(0, 4);

            switch (id)
            {
               case "1234": NavigationService.Navigate(new Uri("/PrincipalPivotPage.xaml", UriKind.Relative)); break; // While I am debugging the error is showing here ....??***

               case "0820": NavigationService.Navigate(new Uri("/StudentsPivotPage.xaml", UriKind.Relative)); break; // While I am debugging the error is showing here ....??**

               default: MessageBox.Show("Oops..!!Correct Your Enrollment Number...."); break;
            }                
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }   

我不知道为什么会发生这种事情,任何人都可以解释...... ??

1 个答案:

答案 0 :(得分:0)

您能否确保相对于您的应用程序目录存在/PrincipalPivotPage.xaml和/StudentsPivotPage.xaml??

new Uri("/PrincipalPivotPage.xaml", UriKind.Relative)