title: NullPointerException while populating an Array or a list
body: <p>I'm trying to populate an array with the another array of values and doing the same with lists but getting null pointer exception for arrays and nothing happened using the list. below is the code snippet:</p>
  
  <pre><code>public class EMPTest {
      public static void main(String[] args) {
          //Array
          EMP[] emps = new EMP[(5)];
          String[] values = {"2","4","6","8","10"};
          for(int i=0; i&lt;emps.length; i++){
              for(int j=0; j&lt;values.length; j++){
                  emps[i].setId(values[j]); //NullPointerException happened here
                  emps[i].setName(values[j]);
                  emps[i].setDep(values[j]);
                  emps[i].setSal(values[j]);
              }
          }
          System.out.println("emps: "+emps);
          //List
          List&lt;EMP&gt; empL = new ArrayList&lt;EMP&gt;(5);
          List&lt;String&gt; val = new ArrayList&lt;String&gt;();
          val.add("a");
          val.add("b");
          val.add("c");
          val.add("d");
          val.add("e");
  
          List&lt;EMP&gt; storedEMPs = null;
          for(EMP e : empL){
              for(String vals : val){
                  e.setId(vals);
                  e.setName(vals);
                  e.setSal(vals);
                  e.setDep(vals);
                  storedEMPs.add(e);
              }
          }
          System.out.println("Populated EMPs: "+storedEMPs);
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at com.test.EMPTest.main(EMPTest.java:12)
  </code></pre>