所以即時獲取此錯誤,我不明白爲什麼即時獲取它。我試圖尋找答案,但每個問題都是如此獨特,以至於他們不適用於我的問題。附加信息:未將對象引用設置爲對象的實例
這是我到目前爲止。
class customer{
public string sFirstName { get; set; }
public string sLastName { get; set; }
public int iAge { get; set; }
}
class customerObject{
public static List<customer> lstStaticUsers { get; set; }
public customerObject(){
lstStaticcustomer = new List<customer>();
}
public static void AddNewStaticUser(string FirstName, string LastName, int Age)
{
lstStaticcustomer.Add(new customer{sFirstName = FirstName, sLastName = LastName, iAge = Age});
}
}
這裏是我的窗口
public partial class wndCustomerInfo : Window
{
public wndCustomerInfo()
{
InitializeComponent();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Hide();
e.Cancel = true;
}
private void btnSubmitForm_Click(object sender, RoutedEventArgs e)
{
customerObject.AddNewStaticcustomer(txtFirstName.Text, txtLastName.Text, Convert.ToInt32(txtAge.Text));
lblMessage.Content = "Created new user: " + txtFirstName.Text;
}
}
那麼這裏就是打開上述
public partial class MainWindow : Window
{
wndCustomerInfo wndCustomerInfoForm;
public MainWindow()
{
InitializeComponent();
Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
wndCustomerInfoForm= new wndCustomerInfo();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
this.Hide();
wndCustomerInfoForm.ShowDialog();
this.Show();
}
}
的一個。如果有人可以幫助這將是偉大的我的主窗口。 IM樣的新的C#,所以請好的
堆棧跟蹤請。 – Aron
可能重複[什麼是NullReferenceException,我該如何解決它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – nvoigt