本帖最后由 King_returns 于 2009-12-25 15:03:45 编辑

解决方案 »

  1.   

    看下你的代码
    当向richtextbox 中显示字符时 ??
      

  2.   

    代码如下:我开打一个文件 ,能在richtextbox中显示,但是会出现 这个提示“未将对象引用设置到对象的实例”
    private void openToolStripMenuItem_Click(object sender, EventArgs e)
            {
                OpenFileDialog file = new OpenFileDialog();
                            richTextBox1.Text = " ";
                file.FileName = "";            file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹,可以使用System.Environment类的静态方法GetFolderPath()。            file.Filter = "Text Document(*.txt)|*.txt|Html Document (*.html)|*.html|All Files|*.*";
                file.FilterIndex = 2;
                file.ValidateNames = true;     //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名            file.CheckFileExists = true;  //验证路径有效性            file.CheckPathExists = true; //验证文件有效性
                try
                {
                    if (file.ShowDialog() == DialogResult.OK)
                    {
                        StreamReader str = new StreamReader(file.FileName, System.Text.Encoding.Default);                    string strWebText = str.ReadToEnd();
                        //      this.textBox3.Text = strWebText;
                        //     this.Text = file.FileName;                    beginParseHtml(strWebText);
                        viewParseHtml(strWebText);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }      
          }
             public void beginParseHtml(string html)
            {
                parserHtml bph = new parserHtml();                       BitTokenContext bitTokenContext = bph.Parse(html);
                BitTokenList ptokenList = bitTokenContext.TokenList;
                while ((ptokenList = ptokenList.Next) != null)
                {
                    if (ptokenList.Token.IsEnd)
                    {
                        richTextBox1.Text = richTextBox1.Text + "/" + ptokenList.Token.Type.ToString() + "\r\n";
                        
                    }
                    else
                    {
                        richTextBox1.Text = richTextBox1.Text + ptokenList.Token.Type.ToString() + "\r\n";                }
                    if (ptokenList.Token.Type == HTMLElement.HTML_TEXT)// 显示TEXT
                    {
                        richTextBox1.Text = richTextBox1.Text + "  " + ptokenList.Token.Data + "\r\n";                }
                    BitTokenAttrList tokenAttrList = ptokenList.Token.AttrList;                while ((tokenAttrList = tokenAttrList.Next) != null)
                    {
                        //
                        richTextBox1.Text = richTextBox1.Text + "  " + tokenAttrList.Attr.Type + "=" + tokenAttrList.Attr.Value + "\r\n";                }//while ((tokenAttrList = tokenAttrList.Next) != null)
                }//while ((tokenList = tokenList.Next) != null)
            }//beginParseHtml
      

  3.   

    "未将对象引用设置到对象的实例" 这个错误一般是因为你的值是NULL引起的
      

  4.   


    我在网上查了 说是什么值 是NULL ,我不知道 那里 错了,知道的 麻烦帮我 ,看下哪里有问题?
      

  5.   

    可以运行,打开文件也可以将文件中的数据处理后显示到richtextbox中,就是会提示:未将对象引用设置到对象的实例。逐语句 运行也没有错误。。
      

  6.   

    我这样改的,还是不能if(richTextBox1!=null)
    {
         while ((ptokenList = ptokenList.Next) != null)
          {
             ...........
          }} 
      

  7.   

    没有NEW 吗?按说richtextbox直接拖上去的啊!不可能出现这个现象啊!你把那个richTextBox1 = new richTextBox();删了吗?
      

  8.   

    支持3楼的说法,判断一下你要加的值是否为空不是判断richtextbox为空