I'm trying to add list of string to HashMap, I have shown below the way I'm trying to do. But I'm getting null point exception (I have commented in the code where I'm getting the exception). Can anyone spot what is the mistake I'm making.
private List<Product> mCartList;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
List<String> listdescription = new ArrayList<String>();
List<String> listcrust = new ArrayList<String>();
List<String> listsize = new ArrayList<String>();
String descriptionString;
String crustString;
String sizeString;
for (int i = 0; i < mCartList.size(); i++) {
mCartList.get(i).selected = false;
hot_number = mCartList.size();
if (mCartList.get(i).description != null
&& !mCartList.get(i).description.isEmpty()) {
descriptionString = mCartList.get(i).description;
listdescription.add(descriptionString);
System.out.println("listdescription = " + listdescription);
}
if (mCartList.get(i).crust != null
&& !mCartList.get(i).crust.isEmpty()) {
crustString = mCartList.get(i).crust;
listcrust.add(crustString);
System.out.println("listcrust = " + listcrust);
}
if (mCartList.get(i).size != null
&& !mCartList.get(i).size.isEmpty()) {
sizeString = mCartList.get(i).size;
listsize.add(sizeString);
System.out.println("listsize = " + listsize);
}
}
listDataChild.put("listcrust", listcrust); // error occurs here
listDataChild.put("listsize", listsize);
listDataHeader.addAll(listdescription);
System.out.println("listDataChild = " + listDataChild);
System.out.println("listDataHeader = " + listDataHeader);
I have debugged and got the value for listsize
in 88 line, but when I pass the line 93 the it gives the below mentioned exception.
Exception screen shot