NullpointerExeption when get element from an ArrayList
<p>I just want to get the first few elements from a list. But when I do this, there's a null pointer at line</p>

<pre><code>returnList.add(returnList1.get(i))
</code></pre>

<p>I tested the <code>returnList1</code>. It has values.</p>

<pre><code>ArrayList&lt;someObject&gt; returnList1 = new ArrayList&lt;someObject&gt;();
ArrayList&lt;someObject&gt; returnList = new ArrayList&lt;someObject&gt;();
returnList1=bunruiSummaryService.getFromDB(param);
int j = 10;
if(returnList1.size() &lt; j){
    j = returnList1.size();
}
for(int i = 0; i&lt;j; i++){
    returnList.add(returnList1.get(i));
}
</code></pre>
