2016-10-15 74 views
0

我使用XStream庫解析一些xml文件。結果是每個文件的映射。當我進行調試時,結果圖就是我正在尋找的內容,但是當我轉到下一行時,地圖的值將變得非常藍!但是它不會在for循環中進行下一輪,它包含下一個文件的信息。什麼會導致它?HashMap的值如何變化?

public class Debug { 
public String path = "E:\\Projects\\svn\\FANRPProduction\\WMS\\src\\main\\resources\\wms\\bpmn\\bp"; 
public XStream xStream; 
public Map<String, List<CallActivity>> bpTpMap; 

public void findBPandTP() throws IOException { 
    File root = new File(path); 
    File[] xmlFiles = FindAllXMLFiles.recursive(root); 

    bpTpMap=new HashMap<String, List<CallActivity>>(); 
    for (File xml : xmlFiles) { 
     if (xml != null) { 
      xStream = new XStream(new StaxDriver()); 
      xStream.alias("definitions", CallActivity.class); 
      xStream.registerConverter(new CallActivityConverter()); 
      bpTpMap = (Map) xStream.fromXML(xml);//Here I get correct information. For example "WMS_RBP_OutgoingWeighing" 
      List<String> bpList = new ArrayList<String>(bpTpMap.keySet()); //Here I see the name of the next file in the path in bpTpMap, which is "WMS_BP_WeighingConfiguration" 
     } 
    } 
} 

}

回答

0

我建議你用下面的調試:

bpTpMap = (Map) xStream.fromXML(xml);//Here I get correct information. For example "WMS_RBP_OutgoingWeighing" 

System.out.println(bpTpMap.size()); 
Set<String> setOfKeys = bpTpMap.keySet(); 
System.out.println("Initial value of keys:"+bpTpMap);//Here you would see any extra values if the map has it 
+0

感謝。 IntelliJ被撞毀了。我的問題解決了。 – Behnaz