Declare array in java
<p>When I declare an array in java I get this error when running: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException. Despite that the variable totalNumbers has a value. It's working when I replace that variable into a number like 5. Must it be a number when declare array? </p>

<pre><code>int randomNumbers[];
randomNumbers = new int[totalNumbers];
</code></pre>

<p>Added some more code, but's the variable names and comments are in swedish! But perhaps the code could be understodd despite of that!? Or why not learn some swedish!= :)</p>

<pre><code>// deklarera arrays för tal under 500 och för tal över 500
int slumptalMindre[];
slumptalMindre = new int[antalSlumptalMindreÄn500];

int slumptalStörre[];
slumptalStörre = new int[antalSlumptal - antalSlumptalMindreÄn500];

//gå genom första array och omplacera tal till ny array
for(int x = 0; x &lt; antalSlumptal; x++) {
    if(slumptal[x] &lt; 500) {

        slumptalMindre[x] = slumptal[x];
    }

}
</code></pre>
