2012-12-20 51 views
0

我想在其他頁面上顯示錯誤消息。我得到了NullReferenceException,但查詢字符串設置在有錯誤的頁面上。有人會告訴我我的代碼有什麼問題嗎?設置查詢字符串,但仍然得到NullReferenceException

catch (Exception ex) 
     { 
      //Dispatcher.BeginInvoke(new Action(() =>MessageBox.Show(ex.StackTrace,"Error!",MessageBoxButton.OK))); 

      string [email protected]"/ErrorPage.xaml?msg=" + ex.StackTrace.ToString() ; 
      Dispatcher.BeginInvoke(new Action(() =>this.NavigationService.Navigate(new Uri(query, UriKind.Relative)))); 
     } 

有用於顯示網頁時其他網頁上加載

public ErrorPage() 
    { 
     InitializeComponent(); 
     string msg = NavigationContext.QueryString["msg"].ToString(); 
     lstMessage.Items.Add(msg); 

    } 
+0

檢查StackTrace是否超過260個字符?並嘗試使用Uri.EscapeUriString – onmyway133

+0

@entropy它是670個字符。我改變方法來顯示消息。我將它們存儲爲全局變量,所以在下一頁我可以得到它。謝謝 –

回答

0

我應該把我的代碼到MainPage_Load方法錯誤消息的代碼。有用。

 public ErrorPage() 
    { 
     InitializeComponent(); 
     this.Loaded += new RoutedEventHandler(MainPage_Loaded);      
    } 

    private void MainPage_Loaded(object sender, RoutedEventArgs e) 
    { 
     MessageBoxResult result = MessageBox.Show(CMSPhoneApp.App.GlobalVariables.strNofifyEmailSubject, 
         "Report Error", MessageBoxButton.OKCancel); 
     if (result == MessageBoxResult.OK) 
     { 
      //according to the serach it works on real devices (not on the emulator) 
      //the reason the EmailComposer not pop up because can't set up an email account on the emulator 
      EmailComposeTask emailcomposer = new EmailComposeTask(); 
      emailcomposer.To = CMSPhoneApp.App.GlobalVariables.reportAddress; 
      emailcomposer.Subject = CMSPhoneApp.App.GlobalVariables.strNofifyEmailSubject; 
      emailcomposer.Body = CMSPhoneApp.App.GlobalVariables.errorMsg; 
      emailcomposer.Show(); 

     } 
     else 
     { 
      App.GoBack(); 
     } 
    } 
相關問題