【发布时间】:2010-02-12 12:06:36
【问题描述】:
class{
public HashMap<String, String> eachperson;
apple(){
this.eachperson.put("thekey","thevalue");
}
}
(请原谅类和函数前面的公共/私有。我只是想知道我是否正确放置了哈希映射。)
真实代码见下图:
class ParsedDataSet{
public HashMap<String, String> eachperson;
public List<HashMap<String,String>> peoplelist = new ArrayList<HashMap<String,String>>();
}
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<String,String>(); //Reached a new item. So reset the temporary hashmap.
}
}
public ParsedDataSet getParsedListData(){
return this.dset;
}
}
【问题讨论】:
-
错误是什么?不要只说“为什么我不能?”
-
我不知道错误,因为我在做Android,它会弹出这个奇怪的编辑源的东西。
-
在 Eclipse 或其他中创建一个新项目,看看编译器对此有何评论,您可能会遇到其他错误,但请查找描述您的 hashmap 内容的错误,可能与运行时环境有关(很可能)。
-
将此标记为“Android”问题。并在 Eclipse 中检查您的 Logcat 窗口(在“DDMS”透视图中可用 - developer.android.com/intl/fr/guide/developing/eclipse-adt.html)
-
顺便说一句,你不需要每个人面前的“这个”。