I am parsing XML file and writing data to hashmap, but when I am using the below code I am facing the error
“The method put(String, Double[]) in the type HashMap
is not applicable for the arguments (String, double)”
ArrayList<HashMap<String, Double[]>> mylist = new ArrayList<HashMap<String, Double[]>>();
for (int i = 0; i < children.getLength(); i++) {
HashMap<String, Double[]> map = new HashMap<String, Double[]>();
Element e = (Element)children.item(i);
HashMap<String, Double[]> map = new HashMap<String, Double[]>();
map.put("id",(Double.parseDouble(ParseXMLMethods.getValue(e, "EMP_ID"))));
mylist.add(map);
}
How do I change so that it would match with the method definition?
This is because this line:
Is trying to put a “Double” type in a map which expects a “Double[]” type. The following would be correct:
because you’re wrapping the single value into an array, which matches the type expected in your map.