Take the 2-minute tour ×

im getting this error of null reference

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

        Cont = 0;
        myStrings = new List<string>();
        str = new ArrayList();
        strs =new string[27];   
            strs[i] = "";

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

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

share|improve this question
Don't use ArrayList. –  SLaks Aug 12 '12 at 2:39
Where do you get the error? –  SLaks Aug 12 '12 at 2:41
What line? What stack trace? –  SLaks Aug 12 '12 at 2:43
When and where is AddTexture being called? –  Luke Wyatt Aug 12 '12 at 2:52
@Habib - It was declared but not initialize I'm assuming. –  Luke Wyatt Aug 12 '12 at 3:00
show 22 more comments

2 Answers

up vote 1 down vote accepted

All good, I was a little late though:

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

share|improve this answer
add comment

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

share|improve this answer
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 3:09
add comment

Your Answer


