public static HashMap parse(InputStream in) throws Exception {
HashMap propertyMap = new HashMap();
SAXReader reader = new SAXReader();
Document document = reader.read(in);
Element root = document.getRootElement();
Iterator i = root.elementIterator("windowId");
while(i.hasNext()) {
Element windowElement = (Element) i.next();
Attribute attribute = windowElement.attribute("name");
String windowId = attribute.getStringValue();
List propertyList = new ArrayList();
for (Iterator j = windowElement.elementIterator( "property" );j.hasNext();){
Element propertyElement = (Element) j.next();
propertyList.add(propertyElement.getStringValue());
}
System.out.println(windowId);
for(int k=0;k<propertyList.size();k++){
System.out.println(propertyList.get(k));
}
propertyMap.put(windowId,propertyList);
}
return propertyMap;
}从配置文件中读取每个windowId的property属性值,将windowId作为key,
该windowId的property组成的list为value,存进HashMap中,
从console输出的信息看,读取文件不存在任何问题,且每个windowId均不相同,为何存放了10次,而最后HashMap中只有8个呢?

解决方案 »

  1.   

    没有相同值
    而且我每次存放之前都是用的List propertyList = new ArrayList();
    即使list里面的值完全相同,也不应该覆盖吧。
      

  2.   

    好像HashMap不允许有相同的key。
      

  3.   

    ============Gen0010XXXXX=============
    materialName
    averageSize
    quantity
    packagedForm
    expectedDate
    ============Gen0020XXXXX=============
    supplierDeliveryDate
    orderNo
    materialName
    averageSize
    orderAmount
    unit
    unitCost
    amount
    resultMessage
    ============Gen0030XXXXX=============
    arrivalQuantity
    erLotNo
    division
    loss
    orderNo
    materialName
    averageSize
    orderAmount
    unit
    unitCost
    amount
    resultMessage
    ============Gen0040XXXXX=============
    checkIsPassed
    arrivalDate
    makerLotNo
    resultMessage
    issueQuantity
    materialName
    averageSize
    arrivalQuantity
    unit
    ============Gen0050XXXXX=============
    factoryLotNo
    ============Gen0060XXXXX=============
    materialName
    averageSize
    usedQuantity
    ============Gen0070XXXXX=============
    orderNo
    orderDate
    quantity
    paymentDate
    ============Gen0080XXXXX=============
    stubNo
    materialName
    averageSize
    remainer
    ============Gen0090XXXXX=============
    factoryLotNo
    bottleNo
    materialName
    averageSize
    arrivalDate
    quantity
    resultMessage
    ============Gen0100XXXXX=============
    makerLotNo
    materialName
    averageSize以上是运行时输出的东西,debug发现在put时会覆盖掉2个,但不管是key还是value都完全不相同,晕死了
      

  4.   

    存放第10个时会覆盖掉第8个,每次debug都这样
      

  5.   

    那你用Hashtable测试下
    相对于HashMap Hashtable是线程安全的
      

  6.   

    你打印的值分不清哪个是windowID,每次输出windowID看看,应该是这个有重复,或者都是null值,否则不可能覆盖的。
      

  7.   

    靠,看清楚楼主的话再回答阿System.out.println(windowId);
    for(int k=0;k<propertyList.size();k++){
    System.out.println(propertyList.get(k));
    }
    -------------------------------------------
    ============Gen0010XXXXX=============
    materialName
    averageSize
    quantity
    packagedForm
    expectedDate
    ============Gen0020XXXXX=============
    supplierDeliveryDate
    orderNo
    materialName
    averageSize
    orderAmount
    unit
    unitCost
    amount
    resultMessage
    ============Gen0030XXXXX=============
    arrivalQuantity
    erLotNo
    division
    loss
    orderNo
    materialName
    averageSize
    orderAmount
    unit
    unitCost
    amount
    resultMessage
    ============Gen0040XXXXX=============
    checkIsPassed
    arrivalDate
    makerLotNo
    resultMessage
    issueQuantity
    materialName
    averageSize
    arrivalQuantity
    unit
    ============Gen0050XXXXX=============
    factoryLotNo
    ============Gen0060XXXXX=============
    materialName
    averageSize
    usedQuantity
    ============Gen0070XXXXX=============
    orderNo
    orderDate
    quantity
    paymentDate
    ============Gen0080XXXXX=============
    stubNo
    materialName
    averageSize
    remainer
    ============Gen0090XXXXX=============
    factoryLotNo
    bottleNo
    materialName
    averageSize
    arrivalDate
    quantity
    resultMessage
    ============Gen0100XXXXX=============
    makerLotNo
    materialName
    averageSize
    以上说明这些key阿 value都是没有问题的
    但是做propertyMap.put(windowId,propertyList);时丢失了