Java 为什么我会得到一个空点执行选项?
我希望你能帮助我。当我想将节点列表/节点放入映射时,我会得到一个NullPointerExection:Java 为什么我会得到一个空点执行选项?,java,xmlnode,xmlnodelist,Java,Xmlnode,Xmlnodelist,我希望你能帮助我。当我想将节点列表/节点放入映射时,我会得到一个NullPointerExection: Map <String, NodeList> config = null; public void loadConfiguration() { helper helper = new helper(); NodeList nodes = null; nodes = helper.getXPathFromFile("/root/*", "conf/con
Map <String, NodeList> config = null;
public void loadConfiguration() {
helper helper = new helper();
NodeList nodes = null;
nodes = helper.getXPathFromFile("/root/*", "conf/config.xml");
if (nodes.getLength() > 0) {
for (int i = 0; i < nodes.getLength(); i++) {
String NodeName = nodes.item(i).getNodeName();
NodeList NodeItem = (NodeList) nodes.item(i);
System.out.println(NodeName); // Here the right Name puts out
System.out.println(helper.nodelistToString(NodeItem)); // here right inside XML-Code put out
config.put(NodeName, NodeItem); // Here comes the NullPointerEx.
}
}
}
Map-config=null;
公共void loadConfiguration(){
helper=newhelper();
NodeList节点=null;
nodes=helper.getXPathFromFile(“/root/*”,“conf/config.xml”);
if(nodes.getLength()>0){
对于(int i=0;i
看起来您从未初始化config
映射
改变
Map <String, NodeList> config = null;
Map-config=null;
到
Map config=newhashmap;
您的映射config
为null
,这就是为什么您会得到NullPointerException
。您应该初始化它,例如Map config=newhashmap()代码>调试总是有帮助的!:)这种问题值得回答吗?谢谢你的帮助!!!
Map <String, NodeList> config = new HashMap<String, NodeList>;