Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Collections Arrays Jagged Arrays

William Wendell
William Wendell
904 Points

What does "Object reference not set to an instance of an object" mean?

doesn't accept the code I have despite having what seems to be the right answer

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
       // private int MaxFactor {get;set;}
       // private int [][] Array = new int[MaxFactor][];

        public static int[][] BuildMultiplicationTable(int maxFactor)
        {
            //MaxFactor = maxFactor;
            int[][] array = new int[maxFactor][];

            for(int i = 0; i < array.Length; i++)
            {
                for(int j = 0; j < maxFactor; j++)
                    array[i][j] = i * j;
            }
            return array;
        }
    }

    //public class Arrays
    //{
      //  public int[][]
    //}
}

1 Answer

James Churchill
STAFF
James Churchill
Treehouse Teacher

William,

The error "Object reference not set to an instance of an object" means that you're encountering a "null" value at runtime when you're expecting an object. I would double check how you're initializing the jagged array.

Sometimes I find it helpful to read Microsoft's official documentation on their MSDN website. Check out this page about jagged arrays.

Jagged Arrays (C# Programming Guide) https://msdn.microsoft.com/en-us/library/2s05feca.aspx

Thanks ~James