您好我需要帮助我的代码 我真的很困惑这个错误,我想将值从textBox1(表单1)传递到textBox7(表单2)。 它说NullReferenceException未处理
表单1
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = setIDtruk.getText;
this.Close();
}
catch(Exception)
{
MessageBox.Show("Wrong");
}
}
表格2
public string getText
{
get
{
return textBox7.Text; // error in this statement
}
}
有人可以帮帮我吗? 感谢
答案 0 :(得分:1)
如果在指定的行上得到NullReferenceException,那么我可以看到的唯一原因是testBox7
为空。我们无法真实地告诉您为什么它与您提供的信息无关。
答案 1 :(得分:0)
如果它说NullReferenceException未处理,则可能是因为TextBox7为null。 您可能需要查看代码并查看错过声明的位置。
如果有一个空TextBox是你的代码逻辑的一部分,那么在这种情况下,不要直接返回textBox7.Text,测试它为null,如果是(null)则返回相应的值(如空字符串)。