为了账号安全,请及时绑定邮箱和手机立即绑定

为什么会报空指针异常

为什么会报空指针异常

qq_飞翔的勇气_0 2018-08-06 10:31:30
package com.xml;import java.io.File;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.io.SAXReader;public class Dom4JReaderUtils {  private static final String RESOURCE;  static{    RESOURCE=Dom4JReaderUtils.class.getClassLoader().getResource("peopleList.xml").getPath();  }  public static Document getDocument(){ Document document=null; SAXReader reader=new SAXReader(); try{ document=reader.read(new File(RESOURCE)); }catch(DocumentException e){ e.printStackTrace(); } return document;    }}错误原因是RESOURCE=Dom4JReaderUtils.class.getClassLoader().getResource("peopleList.xml").getPath();Caused by: java.lang.NullPointerException
查看完整描述

1 回答

?
慕勒0069038

TA贡献143条经验 获得超39个赞

文件路径有问题 , 你输出一下 Dom4JReaderUtils.class.getClassLoader().getResource("/").getPath(); 

查看完整回答
反对 回复 2018-08-06
点击展开后面2
  • 1 回答
  • 0 关注
  • 955 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信