如何解決此錯誤類型ArrayList中的方法add(String)不適用於參數HashMap的)。ArrayList <String>類型的方法add(String)不適用於參數(HashMap <String,String>)
我試圖把androidhive.com XML解析自定義列表視圖我的申請
繼承人我的代碼:
private void prepareListData() {
//ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
ArrayList<String> songsList = new ArrayList<String>();
com.test.utilities.XMLParser parser = new com.test.utilities.XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_SONG);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
// adding HashList to ArrayList
songsList.add(map);
}
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, ArrayList<String>>();
// Adding child data
listDataHeader.add("VRP Medical Bay");
//listDataHeader.add("");
//listDataHeader.add("");
// Adding child data
ArrayList<String> listUnderVRP = new ArrayList<String>();
//listUnderVRP.add("eDataClinical");
//listUnderVRP.add("Schedule");
//listUnderVRP.add("Dictate");
//listUnderVRP.add("View Messages");
//listUnderVRP.add("Reports for Signature");
//listUnderVRP.add("View Billing");
//listUnderVRP.add("View State");
listDataChild.put(listDataHeader.get(0), songsList); // Header, Child data
//listDataChild.put(listDataHeader.get(1), nowShowing);
//listDataChild.put(listDataHeader.get(2), comingSoon);
}
是什麼錯誤,你得到時,你取消註釋,你聲明數組列表作爲ArrayList的<的HashMap> –
即時獲取此零件的錯誤\t listDataChild.put(listDataHeader.get(0),songsList);方法put(String,ArrayList)在類型HashMap >不適用於參數(String,ArrayList >) –
user3243065