Richtextbox对象引用未设置为对象的实例
本文关键字:对象 实例 设置 对象引用 Richtextbox | 更新日期: 2023-09-27 18:18:53
为什么我得到这个错误?我的程序是使用。net Framework。对象引用没有设置为对象的实例。
if (this.webBrowser1.Url.AbsoluteUri.Contains("/fire/") && this.richTextBox1.Text.Contains("-"))
this.richTextBox1.Text = this.richTextBox1.Text.Substring(0, this.richTextBox1.Text.IndexOf('-'));
所以我修改了它,把它改成了下面这个,但仍然不起作用:
if (webBrowser1.Url.AbsoluteUri.Contains("/fire/") && richTextBox1.Text.Contains("-")) {richTextBox1.Text = richTextBox1.Text.Substring(0, richTextBox1.Text.IndexOf('-'));}
下面是真正的代码体:
private void button64_Click(object sender, EventArgs e)
{
this.richTextBox2.Refresh();
this.richTextBox1.Refresh();
if (object.Equals((object)this.richTextBox1.Text, (object)this.richTextBox2.Text))
this.label1.BackColor = Color.GreenYellow;
if (!object.Equals((object)this.richTextBox1.Text, (object)this.richTextBox2.Text))
this.label1.BackColor = Color.Orchid;
if (this.webBrowser1.Url.AbsoluteUri.Contains("/fire/") && this.richTextBox1.Text.Contains("-"))
this.richTextBox1.Text = this.richTextBox1.Text.Substring(0, this.richTextBox1.Text.IndexOf('-'));
if (this.webBrowser1.Url.AbsoluteUri.Contains("hell.com/webapp/wcs/stores/servlet/OrderSummaryDisplay?") && this.richTextBox1.Text.Contains(","))
this.richTextBox1.Text = this.richTextBox1.Text.Substring(0, this.richTextBox1.Text.IndexOf(','));
if (this.webBrowser1.Url.AbsoluteUri.Contains("hell.com/webapp/wcs/stores/servlet/OrderSummaryDisplay?") && this.richTextBox2.Text.Contains(","))
this.richTextBox2.Text = this.richTextBox2.Text.Substring(0, this.richTextBox2.Text.IndexOf(','));
if (this.richTextBox1.Text.Contains("-") && !this.richTextBox2.Text.Contains("-"))
this.richTextBox2.Text = this.richTextBox2.Text.Substring(0, this.richTextBox2.Text.IndexOf('-'));
if (!this.richTextBox2.Text.Contains("-") || this.richTextBox1.Text.Contains("-"))
return;
this.richTextBox2.Text = this.richTextBox2.Text.Substring(0, this.richTextBox2.Text.IndexOf('-'));
}
在你的问题中没有足够的细节来确定,但是当你试图访问一个对象的属性为null时,你会得到这个错误。
在你指定的代码行上放置一个断点,检查每个对象是否为空,或者修改代码来检查是否为空:
if (webBrowser1.Url != null && webBrowser1.Url.AbsoluteUri.Contains("/fire/") && .... )