The following code causes null-pointer exception during execution. It just said null pointer exception.
When I put the hotItem class outside of the function, it works without any problem.
Once I put it into the function, it will cause null pointer exception.
I just want to know why this would happen and what is the life cycle of the class inside a function.
private void getHotItem()
{
Gson gsonAdapter = new Gson();
class hotItem
{
private String hotItemPK = "";
}
Type hotItemType = new TypeToken<List<hotItem>>(){}.getType();
List<hotItem> hotItemList = new ArrayList<hotItem>();
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();
}
}
Please Check issue here
Resolution: