function call returns NaN when all types are correct : <p>A function call keeps returning NaN, when taken out of context it works but in context it doesn't</p>

<p>I've tried changing types between double and Double to no avail</p>

<pre><code>private Double average(ArrayList&lt;Double&gt; x){
    Double sum = 0.0;
    for(int i = 0; i &lt; x.size(); i++)
        sum += x.get(i);
    return sum / x.size();
}
</code></pre>

<p>the return is NaN in most cases</p>
