I am trying to parse through a HashMap stored into an ArrayList (Not good at it). I did as I have been told however, I am getting an NullPointerException
Here is my code:
private void populateList() {
list = new ArrayList<HashMap>();
HashMap temp = new HashMap();
temp.put(CODE,"128");
temp.put(SERVICE_CODE, "NRS");
temp.put(SERVICE_GROUP, "Medical Treatment Loan");
temp.put(SERVICE, "Number of referral slip");
list.add(temp);
HashMap temp1 = new HashMap();
temp1.put(CODE,"128");
temp1.put(SERVICE_CODE, "NL");
temp1.put(SERVICE_GROUP, "Medical Treatment Loan");
temp1.put(SERVICE, "Number of Loan");
list.add(temp1);
HashMap temp3 = new HashMap();
temp3.put(CODE,"128");
temp3.put(SERVICE_CODE, "AD");
temp3.put(SERVICE_GROUP, "Medical Treatment Loan");
temp3.put(SERVICE, "Amount disbursed");
list.add(temp3);
}
and here is how I was trying to Iterate through my list:
for (int a =0; a < list.size();a++)
{
HashMap<String, Integer> tmpData = (HashMap<String, Integer>) list.get(a);
Set<String> key = tmpData.keySet();
Iterator it = key.iterator();
while (it.hasNext()) {
String code = ""+tmpData.get(CODE);
String service, service_group;
if(code.equalsIgnoreCase("128"))
{
if(tmpData.get("SERVICE_CODE").toString().equalsIgnoreCase("AD"))
{
service = tmpData.get("SERVICE").toString();
service_group = tmpData.get("SERVICE_GROUP").toString();
tv.setText("code >> "+code + "\nService Code >> "+tmpData.get("SERVICE_CODE").toString()
+"\nservice >> "+service+"\nservice_group >> "+service_group);
}
}
it.remove(); // avoids a ConcurrentModificationException
}
}
My Error:
12-04 19:30:22.887 24861-24861/com.example.monkey.mysql_dump E/AndroidRuntime: java.lang.NullPointerException
12-04 19:30:22.887 24861-24861/com.example.monkey.mysql_dump E/AndroidRuntime: at com.example.monkey.mysql_dump.input_taking$2.onClick(input_taking.java:74)
Basically I am trying to get the last value here, just to see if I can actually go through the whole arrayList. Thank you.