If you get a NullReferenceException on the line you indicate then the only reason that I can see is that testBox7
is null. We can't really tell you why it's null from the information that you've provided.
Object reference not set to an instance of an object textBox
-
19-10-2022 - |
题
Hello i need a help with my code here Im really confused about this error, i want to pass the value from textBox1 (form 1) to textBox7 (form 2). and it said NullReferenceException was unhandled
Form 1
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = setIDtruk.getText;
this.Close();
}
catch(Exception)
{
MessageBox.Show("Wrong");
}
}
Form 2
public string getText
{
get
{
return textBox7.Text; // error in this statement
}
}
can anybody help me out ? thanks
没有正确的解决方案
其他提示
If it says NullReferenceException was unhandled it's probably because your TextBox7 is null. You might need to go through your code and see where you missed a declaration.
If having a null TextBox is part of your code logic, in that case instead of returning the textBox7.Text directly, test it for null and if it is (null) return the appropriate value instead (like an empty string).
不隶属于 StackOverflow