-3

im getting this error of null reference

private int Cont;
private List<string> myStrings;
private ArrayList str;
private string[] strs;

     myclass()
     {
        Cont = 0;
        myStrings = new List<string>();
        str = new ArrayList();
        strs =new string[27];   
        for(int i = 0; i < 27;i++)
        {
            strs[i] = "";
        }
     }

    public void AddTexture(string name)
    { 
        Console.WriteLine("Count "+Cont);
        Console.WriteLine("ive got the texture "+name);
        myStrings.Add(name);
        //strs[Cont] = name;
        //str.Add(name);
        Cont++;
     }

as you see i've tried with list,arraylist and arrays and none of them work when i try to add the first value i get that error i have seriously no idea whats happening i am getting a string in name,and Cont = 0 in the 1st write line

any idea what im doing wrong? thank you the error is whenever im trying to fill the array,arraylist or the list in the function AddTexture after the 2 console.writeline i've commented those 2 lines but thats because those are the ways i tried to use the array,arraylist and the list

Makenshi
  • 993
  • 3
  • 15
  • 28

2 Answers2

1

All good, I was a little late though:

To sum it up, the issue was due to the sequence.

Luke Wyatt
  • 1,126
  • 2
  • 12
  • 23
0

So no-one else reads 30 comments to find out its already solved:

*When and where is AddTexture being called?

Is AddTexture being called before the constructor? – Luke Wyatt*

Wow that was it i was initializing it in 3 different objects and 1 of them was being called before the constructor thank you very much if you post it as answer i will make give you points

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • well this was suppossed to be luke's answer but w/e thank you for posting i was waiting for him tho – Makenshi Aug 12 '12 at 03:09