title: Initialization of a Custom Object array of dimension 2
body: <p>I'm trying to initialize an array (of a class object I created) of 2 dimensions, but I keep on having the same runtime error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPoointerException
      at ........
  </code></pre>
  
  <p>I've managed to do it with primitive types, but not types extending object and I would like to know if it's possible (and if it's the case how).</p>
  
  <p>Here's an exemple of my code:</p>
  
  <pre><code>MyCustomObject[][] matrix = new MyCustomObject[10][10];
  
  for (int i = 0; i &lt; 10; i += 1)
      matrix[i][0] = new MyCustomObject("some arguments ...");
  </code></pre>
  
  <blockquote>
    <p>The error is marked at the line were I try to give a value to the matrix: matrix[i][0] = ....</p>
  </blockquote>
  
  <p>From what I understand after my researches, Java gave the value null to every member of the array, which is okay for me. But why would it mark me an error when I'm trying to replace the null value with an existing one. I'm not calling a method on null.</p>
  
  <h2>EDIT</h2>
  
  <p>Full code:</p>
  
  <pre><code>int sourceLength = source.length(); // Length of a CharSequence
  int targetLength = target.length(); // Length of a CharSequence
  Matrix distanceMatrix[][] = new Matrix[sourceLength][targetLength];
  
  for (int row = 1; row &lt; sourceLength; row += 1) {
      distanceMatrix[row][0] = new Matrix(        // The error is marked at this line.
          distanceMatrix[row - 1][0].cost + option.getDeletionCost(),
          row - 1,
          0
      );
  }
  
  for (int column = 1; column &lt; targetLength; column += 1) {
      distanceMatrix[0][column] = new Matrix(
          distanceMatrix[0][column - 1].cost + option.getInsertionCost(),
          0,
          column - 1
      );
  }
  
  for (int row = 1; row &lt; sourceLength; row += 1) {
      for (int column = 1; column &lt; targetLength; column += 1) {
  
          // do more stuff.
  
      }
  }
  </code></pre>
  
  <p>Matrix class (which is inside the main class):</p>
  
  <pre><code>public final static class Matrix {
  
      public int cost;
      public int row;
      public int column;
  
      public Matrix(int cost, int row, int column) {
          this.cost = cost;
          this.row = row;
          this.column = column;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj instanceof Matrix)
              return (cost == ((Matrix)obj).cost
                  &amp;&amp; row == ((Matrix)obj).row
                  &amp;&amp; column == ((Matrix)obj).column);
          return (super.equals(obj));
      }
  
  }
  </code></pre>
  
  <p>Stack traces:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at net.azzerial.gt.core.Fuzzy.distance(Fuzzy.java:54)
      at net.azzerial.gt.core.Fuzzy.levenshteinDistance(Fuzzy.java:24)
      at net.azzerial.gt.Test.main(Test.java:15)
  </code></pre>