Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is wrong with this Java code? Why can't I put in HashMap?
    primarykey
    data
    text
    <pre><code>class{ public HashMap&lt;String, String&gt; eachperson; apple(){ this.eachperson.put("thekey","thevalue"); } } </code></pre> <p>(Please excuse the public/privates in front of the class and function. I just want to know if I'm putting the hash map correctly. )</p> <p>For the true code, please see below:</p> <pre><code>class ParsedDataSet{ public HashMap&lt;String, String&gt; eachperson; public List&lt;HashMap&lt;String,String&gt;&gt; peoplelist = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;(); } class ListprofileHandler extends DefaultHandler{ private boolean in_results = true; private boolean in_item = false; private boolean in_first_name = false; private boolean in_last_name = false; private boolean in_picture_url = false; private boolean in_enditem_dummy = false; private ParsedDataSet dset = new ParsedDataSet(); public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if(localName.equals("results")){ this.in_results = true; }else if(localName.equals("item")){ this.in_item = true; }else if(localName.equals("first_name")){ this.in_first_name = true; }else if(localName.equals("last_name")){ this.in_last_name = true; }else if(localName.equals("picture_url")){ this.in_picture_url = true; }else if(localName.equals("enditem_dummy")){ this.in_enditem_dummy = true; } } public void endElement(String uri, String localName, String qName)throws SAXException { if(localName.equals("results")){ this.in_results = false; }else if(localName.equals("item")){ this.in_item = false; }else if(localName.equals("first_name")){ this.in_first_name = false; }else if(localName.equals("last_name")){ this.in_last_name = false; }else if(localName.equals("picture_url")){ this.in_picture_url = false; }else if(localName.equals("enditem_dummy")){ this.in_enditem_dummy = false; } } public void characters(char ch[], int start, int length) throws SAXException { if(this.in_first_name){ dset.eachperson.put("first_name", new String(ch, start, length)); } if(this.in_enditem_dummy){ dset.peoplelist.add(dset.eachperson); dset.eachperson = new HashMap&lt;String,String&gt;(); //Reached a new item. So reset the temporary hashmap. } } public ParsedDataSet getParsedListData(){ return this.dset; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload