Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我会得到一个空点执行选项?_Java_Xmlnode_Xmlnodelist - Fatal编程技术网

Java 为什么我会得到一个空点执行选项?

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

我希望你能帮助我。当我想将节点列表/节点放入映射时,我会得到一个NullPointerExection:

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>;