0

I tried to change a TextBox text from another class by doing this :

my form1:

public void showLog(string s)
{
      txtlog.Text = s;
}

and my class:

class Functions
{

    private readonly Form1 form;
    public Functions(Form1 form)
    {
        this.form = form;
    }

    public Functions()
    {

    }
    private void FindDlLinks(string url)
    {
        // line bellow gave me a NullReferenceException error
        form.showLog("something");
    }
}

And the error is :

Object reference not set to an instance of an object.

it works with a simple MessageBox but seems there is something with my TextBox.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
Payam Asefi
  • 2,677
  • 2
  • 15
  • 26
  • 2
    [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Sep 10 '15 at 06:48
  • When you calling FindDlLinks() method make sure your form field is not null, I think in FindDlLinks() method form field is null, are you creating new Functions(Form1 form) cunstractor? – Jamaxack Sep 10 '15 at 06:51

1 Answers1

0

Send this as parameter to the constructor when you are instantiating an instance of Functions. Like this:

Functions fr = new Functions(this);
fr.FindDlLinks("");
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109