0

I have a quick question about a piece of code that I wrote:

for (int x = 0; x < width; x++)
{
    for (int y = 0; y < height; y++)
    {
            map.Add(main.Stone);
            Vector2 vec = new Vector2(x * 16, y * 16);
            pos.Add(vec);
    }
}

I get an error at pos.Add(vec); saying that the reference is null even though I declared it in the line above. I am pretty new to XNA so it's probably something really simple, but I can't seem to figure it out.

2
  • 2
    Where is pos declared and initialized? Commented Jul 3, 2012 at 17:27
  • 1
    pos is null. Check using debugger. Commented Jul 3, 2012 at 17:27

2 Answers 2

1

pos is null.

vec cannot be null as it is declared above using value type entity (integers).

Check using debugger.

Sign up to request clarification or add additional context in comments.

Comments

0

pos is the reference that is null, not vec. Where did you declare pos?

3 Comments

Perhaps the main class was passing in a null value to the method. No way to tell without seeing some more of your code.
It was being declared in my main method, then sent to this class from there via function parameters
Oh >.< I fixed it. I had List<Vector2> Pos; and it wasn't instantiated yet. All I had to do was change it to List<Vector2> Pos = new List<Vector2>();.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.