2011-06-13 64 views
1

我正在尝试以下内容来更新HashMap以及学生的新值,请检查我错过了什么地方。访问相同ArrayList的HashMap

ArrayList<Student> tempStudentList = XMLParser.studentHashMap.get(currentSectionName); 

if(studentList==null) 
{ 

    Log.v(CURRENT_SCREEN,"created another student list for section name:"+currentSectionName); 
    tempStudentList = new ArrayList<Student>(); 

} 
Log.v(CURRENT_SCREEN,"Added student to the list"); 

tempStudentList.add(currentStudent); 

XMLParser.studentHashMap.put(currentSectionName, tempStudentList); 
+0

什么问题,你所看到的:此外,Java集合是可变的,在studentHashMap阵列直接,所以你不需要你的地图上的每个查询后执行另一个放操纵? – seanhodges 2011-06-13 12:37:15

+0

您没有给我们足够的上下文 - 例如,我们不知道发生了什么问题,或者“学生”来自哪里。 – 2011-06-13 12:38:01

回答

3

我想你想写tempStudentList而不是studentList在空检查。

1

您正在检查null的错误变量。

ArrayList<Student> tempStudentList = XMLParser.studentHashMap.get(currentSectionName); 

if(tempStudentList == null) 
{ 
    Log.v(CURRENT_SCREEN, "created another student list for section name:"+currentSectionName); 
    tempStudentList = new ArrayList<Student>(); 
    XMLParser.studentHashMap.put(tempStudentList); 
} 

tempStudentList.add(currentStudent); 
Log.v(CURRENT_SCREEN,"Added student to the list");