2016-10-15 2 views
0

Ich Pars einige XML-Dateien mit XStream-Bibliotheken. Das Ergebnis ist eine Karte für jede Datei. Wenn ich debugge, ist die Ergebniskarte, was ich suchte, aber wenn ich zur nächsten Zeile gehe, ändert sich der Wert der Karte aus heiterem Himmel! Es geht jedoch nicht für die nächste Runde in der "for" -Schleife, es enthält die Informationen der nächsten Datei. Was kann das verursachen?Wie ändert sich der Wert von 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" 
     } 
    } 
} 

}

Antwort

0

Ich würde Ihnen vorschlagen, mit dem folgenden debuggen:

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

Dank. IntelliJ wurde abgestürzt. Mein Problem wurde gelöst. – Behnaz

Verwandte Themen