【问题标题】:"object reference not set to an instance of an object " getting an error?“对象引用未设置为对象的实例”出现错误?
【发布时间】:2014-06-04 10:42:53
【问题描述】:

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

  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);
        }

    }   

我不知道为什么会发生这种情况,谁能解释...??

【问题讨论】:

    标签: object reference set


    【解决方案1】:

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

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

    【讨论】:

    • 它正在导航到该页面,但导航后显示上述错误...任何想法..??
    猜你喜欢
    • 1970-01-01
    • 2011-07-09
    • 2012-08-31
    • 2011-11-21
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多