title: Java Null Pointer Exception with array of ArrayList
body: <p>I have found many related post here but couldn't get my answer.Why this run-time error ?</p>
  
  <pre><code>static List&lt;Integer&gt;[] adj = (List&lt;Integer&gt;[]) new ArrayList[1000];
  
      public static void main(String[] args) {
          int edge, u, v, source;
          Scanner input = new Scanner(System.in);
          edge = input.nextInt();
          for (int i = 0; i &lt; edge; i++) {
              u = input.nextInt();
              v = input.nextInt();
              adj[v].add(u); // Null pointer Exception
              adj[u].add(v); // Null pointer Exception
          }
  </code></pre>