Why am I getting NullPointerExceptions after assigning references in arrays in a loop?
<p>Why this is not working:</p>

<pre><code>//...
Integer[] array=new Integer[5];
for(Integer x: array){x=-1;}
printArray(array);
//...

// the print function is the following
public static String printArray(Object[] array){
    String str="";
    for(Object obj : array){
         str+=obj.toString()+" ,";
    }
    System.out.println(str);
}
</code></pre>

<p>I got NullPointerException at the for-each statement from the printArray function, why?</p>
