0

i been trying to link constructors but i been having issues as i have a lot of different classes witch share a lot of info with each other as so as it stands currently this is what i want to do

get one of the classes to reverence form1 so i can run a certain method

so this is what i have tryied so far

gscadding.cs

public SoundAlis sounds;
public addingweapons dlc3gsc;
public Form1 elfgsc;
public gscadding elfy;
private gscadding elfy1;
public gscadding(addingweapons dlc3)
{
    dlc3gsc = dlc3;
}

public gscadding(gscadding elfy1)
{
    // TODO: Complete member initialization
    this.elfy1 = elfy1;
}

this is the class i want to get into form one to use a function i made in form 1

this is what i have in form1

elfenlied_program_settings elf;
addingweapons elf_weap;
Parser elfenliedl;
gscadding elfy;

//Parser parser = new Parser("model1887_sp");

public Form1()
{

    InitializeComponent();

    updater1.CheckForUpdates();
    listBoxAdv1.Visible = false;
    elf = new elfenlied_program_settings(listBoxAdv1,elfenliedl);
    elf_weap = new addingweapons(richTextBoxEx1);
    elfenliedl = new Parser("model1887_sp");
    elfy = new gscadding(elfy);
    timer1.Start();
    elf.buttonX2 = buttonX2;
    elf.elfenform = this;
   // elfe.elfgsc = this;
    buttonX2.Visible = false;
    buttonX3.Enabled = true;
    textBoxX6.Enabled = false;
    elfenliedl.buttonX1 = buttonX1;

basicly what im trying to do is form gscadding.cs to call a function called updatesettings();

witch when the form loads and i select a path it updates all string = paths

but i keep getting the

Error I get

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    Possible duplicate of [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) – Preston Guillot Dec 24 '15 at 20:24
  • This is very confuse. Why do you have an instance of gscadding inside of itself? – jpgrassi Dec 24 '15 at 20:32
  • Please find a programming style for you and stick with it. That looks like you used an obfuscator before posting the source here. – nvoigt Dec 24 '15 at 20:46

1 Answers1

1

elfgsc is null you have to set it.

public gscadding(addingweapons dlc3, Form1 form)
    {
        dlc3gsc = dlc3;
        elfgsc = form;
    }

In your form constructor

elfy = new gscadding(elfy, this);

Now you can call methods in your form from your gscadding class like so:

elfgsc.updatesettings();

As to your second error, passing elfy to itself is useless. Remove elfy and replace with elfy_weap

Axis
  • 826
  • 7
  • 22
  • i should have mentioned only just rememberd i have it in another cs as well here is a ghostbin of all the code https://ghostbin.com/paste/hvrem because it still gives me errors and i dont know why its not like i have not done this already multible times – Saito Hiraga Dec 24 '15 at 20:50
  • Why are you passing elfy to itself? That doesn't make any sense. Remove public gscadding(gscadding elfy1) { // TODO: Complete member initialization this.elfy1 = elfy1; } – Axis Dec 24 '15 at 21:25
  • See the second part of the answer to fix your new problem. – Axis Dec 24 '15 at 21:29
  • ok main form http://i.imgur.com/FtFDki3.png gscadding http://i.imgur.com/deArIcG.png changed things and still get does not exist in current contex error – Saito Hiraga Dec 24 '15 at 22:33
  • You still have it a little backwards... In Form1 constructor it should be elfy = new gscadding(elf_weap, this); – Axis Dec 24 '15 at 22:44
  • yeah i did that and it still says null revrence in the error – Saito Hiraga Dec 24 '15 at 23:05