NullPointerException when adding an Item to the list
<p>Helo All,</p>

<p>I have a problem that I am facing NullPointerException when I want to add an item to the List, as shown below:</p>

<pre><code>public List&lt;SearchResponse&gt; sortMPGListViewForNA(List&lt;SearchResponse&gt; response)
    {
        List&lt;SearchResponse&gt; list = response;
        List&lt;SearchResponse&gt; tempMPG = null, tempPrice = null, tempRating = null;
        for(int i=0;i&lt;response.size();i++)
        {
            if(response.get(i).years.get(0).mpg.equalsIgnoreCase("n/a"))
            {
                tempMPG.add(response.get(i));
                list.remove(i);
            }
            if(response.get(i).years.get(0).price.equalsIgnoreCase("n/a"))
            {
                tempPrice.add(response.get(i));
                list.remove(i);
            }
            if(response.get(i).years.get(0).rating.equalsIgnoreCase("n/a"))
            {
                tempRating.add(response.get(i));//NPE Occurs Here
                list.remove(i);
            }
        }
        response.addAll(tempMPG);
        response.addAll(tempPrice);
        response.addAll(tempRating);
        return response;
    }
</code></pre>

<p>Please suggest me any solution regarding to the same.</p>

<p>Thanks in advance.</p>
