title: Creating Matrix using Arrays
body: <p>i was given an assignment to do, writing a class array and class Matrix, the matrix class is going to use array class to create its matrix, it is like an array pointing on other arrays, my problem is everything went fine but when i tried to do the addition of of two matrix that i created i keep having NullPointerException, this is my entire code. i have pointed on my error in the code below thanks.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Matrix {
      public Vector mat[];
      public static int m;
      static int i, j;
      Scanner sc;
  
      Matrix() {
          m = 0;
          mat = null;
      }
  
      Matrice(int m, int n) {
          Matrix.m = m;
          Vector.n = n;
          mat = new Vector[100];
          // mat[i]=new Vector(100);
      }
  
      public void fillmatrix() {
          mat = new Vector[100];
          sc = new Scanner(System.in);
          System.out.println("enter the number of the rows");
          Matrix.m = sc.nextInt();
          System.out.println("enter the number of your columns");
          Vector.n = sc.nextInt();
          for (j = 0; j &lt; m; j++) {
              mat[j] = new Vector(Vector.n);
              mat[j].fillmatrix();
          }
      }
  
      public void DisplayMatrix() {
          System.out.println("Th matrix you have entered: ");
          for (i = 0; i &lt; Vector.n; i++) {
              mat[i].Display();
          }
  
          public static Matrix Addition(Matrix mat1, Matrix mat2) {
              Matrix mat3 = new Matrix();
              for (j = 0; j &lt; Vector.n; j++) {
                  for (i = 0; i &lt; Matrix.m; i++) {
                      mat3.mat[i].t[j] = (mat1.mat[i].t[j]) + (mat2.mat[i].t[j]); &lt; -- -- -- -- - where the mistake but i can 't solve it ://&gt;
                  }
  
              }
              return mat3;
          }
      }
  
      public static void main(String args[]) {
          Matrix Mat1 = new Matrix();
          Matrix Mat2 = new Matrix();
          Matrix Mat3 = new Matrix();
          Mat1.fill();
          Mat1.affiche2();
          Mat2.fill();
          Mat2.affiche2();
          Mat3 = Matrix.Addition(Mat1, Mat2);
          Mat3.affiche2();
      }
  
      import java.util.Scanner;
  
      public class Vector {
          public static int n;
          static int i;
          static int j, k;
          int t[];
          static Scanner sc = new Scanner(System.in);
  
          Vector(int n) {
              Vector.n = n;
              t = new int[100];
          }
  
          Vector() {
              Vector.n = 0;
              t = null;
          }
  
          public void fill() {
              t = new int[100];
              sc = new Scanner(System.in);
  
              for (i = 0; i &lt; n; i++) {
                  System.out.println("enter " + i + "° element of your array");
                  t[i] = sc.nextInt();
              }
          }
  
          public void contain(Vector Tab) {
              i = 0;
              j = 0;
              if (n &lt;= Tab.t.length) {
                  while (j &lt; Tab.t.length) {
                      if (t[i] != Tab.t[j]) {
                          j++;
                          i = 0;
                      } else {
                          i++;
                          j++;
                      }
                  }
                  if (i &gt; n) {
                      System.out.println("the array 1 is contained in array 2");
                  }
                  els
                  System.out.println("the array 1is not contained in array2");
              }
          } else {
              while (i &lt; n) {
                  if (t[i] != Tab.t[j]) {
                      i++;
                      j = 0;
                  } else {
                      i++;
                      j++;
                  }
              }
              if (j &gt; n) {
                  System.out.println("the array 2 is contained in array 1");
              } else {
                  System.out.println("the array 2 is contained in array 1");
              }
          }
      }
  
      boolean appartient(int x) {
          i = 0;
          boolean found = false;
          while ((i &lt; n) &amp;&amp; (t[i] != x)) {
              i++;
          }
          if (i &gt;= n)
              System.out.println("le x n'appartient pas a votre Tableau");
          else {
              System.out.println("le x appartient a votre tableau");
              found = true;
          }
          return found;
      }
  
      public void Display() {
          for (i = 0; i &lt; n; i++) {
              System.out.println(t[i]);
          }
      }
  
      public void Order() {
          int j, tmp;
          for (i = 0; i &lt; n; i++) {
              for (j = i + 1; j &lt; n; j++) {
                  if (t[i] &gt; t[j]) {
                      tmp = t[i];
                      t[i] = t[j];
                      t[j] = tmp;
                  }
              }
          }
          for (int i = 0; i &lt; n; i++) {
              System.out.println("your array ordered  " + t[i]);
          }
      }
  
      void inser(int x) {
          if (appartient(x) == true) {
              System.out.println("Insersion is impossible, the value already exist");
          } else {
              for (i = n;
                  (i &gt; 0) &amp;&amp; (t[i - 1] &gt; x); i--)
                  t[i] = t[i - 1];
  
              t[i] = x;
              n++;
              for (i = 0; i &lt; n; i++)
                  System.out.println(t[i]);
          }
      }
  
      public static void fusionner(Vector tab1, Vector tab2) {
          Vector FUS = new Vector(tab1.t.length + tab2.t.length);
          i = 0;
          j = 0;
          k = 0;
          while ((i &lt; tab1.t.length) &amp;&amp; (j &lt; tab2.t.length))
              if (tab1.t[i] &lt; tab2.t[j]) {
                  FUS.t[k] = tab1.t[i];
                  k++;
                  i++;
              } else {
                  FUS.t[k] = tab2.t[j];
                  k++;
                  j++;
              }
  
          while (i &lt; n) {
              FUS.t[k] = tab1.t[i];
              k++;
              i++;
          }
          while (j &lt; n) {
              FUS.t[k] = tab2.t[j];
              k++;
              j++;
          }
  
          System.out.println("your arrays after the fusion is ");
          for (k = 0; k &lt; tab1.t.length + tab2.t.length; k++)
              System.out.println(FUS.t[k]);
      }
  
      public static void main(String args[]) {
          Vector tab1 = new Vector();
          System.out.println("Enter n");
          n = sc.nextInt();
          tab1.fill();
          tab1.Display();
          tab1.trier();
          Vector tab2 = new Vector();
          tab2.fill();
          tab2.affiche();
          tab2.trier();
          fusionner(tab1, tab2);
          tab1.contain(tab2);
          tab2.appartient(5);
          tab1.inser(6);
      }
  }
  </code></pre>