Class inside a function causing null pointer exception
<p>The following code causes null-pointer exception during execution. It just said null pointer exception.</p>

<p>When I put the hotItem class outside of the function, it works without any problem.</p>

<p>Once I put it into the function, it will cause null pointer exception.</p>

<p>I just want to know why this would happen and what is the life cycle of the class inside a function.</p>

<pre><code>private void getHotItem()
{   
    Gson gsonAdapter = new Gson();
    class hotItem
    {
        private String hotItemPK = ""; 
    }
    Type hotItemType = new TypeToken&lt;List&lt;hotItem&gt;&gt;(){}.getType();
    List&lt;hotItem&gt; hotItemList = new ArrayList&lt;hotItem&gt;();

    try
    {
        itemAccess.getHotItemList();
        itemAccess.start();
        itemAccess.join();
        hotItemList = gsonAdapter.fromJson(returnData, hotItemType);

        if(!hotItemList.isEmpty())
        {
            testText.setText(hotItemList.get(0).hotItemPK.toString());
        }
    }
    catch (InterruptedException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
</code></pre>
