当前位置: 技术问答>java相关
用jdom解析xml的问题!!!(急!!在线等待)
来源: 互联网 发布时间:2017-04-06
本文导语: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder=factory.newDocumentBuilder(); Document doc=builder.parse("links.xml"); 以上代码运行到Document doc=builder.parse("links.xml");就出现下面错误究竟是什么...
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("links.xml");
以上代码运行到Document doc=builder.parse("links.xml");就出现下面错误究竟是什么意思??
java.lang.NullPointerException
at weblogic.xml.jaxp.RegistryDocumentBuilder.getFactoryFromEntities(RegistryDocumentBuilder.java:315)
at weblogic.xml.jaxp.RegistryDocumentBuilder.getCustomDocumentBuilderFactory(RegistryDocumentBuilder.java:227)
at weblogic.xml.jaxp.RegistryDocumentBuilder.getDocumentBuilder(RegistryDocumentBuilder.java:197)
at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:133)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:134)
at xmlwriter.xmlwriter.main(xmlwriter.java:15)
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc=builder.parse("links.xml");
以上代码运行到Document doc=builder.parse("links.xml");就出现下面错误究竟是什么意思??
java.lang.NullPointerException
at weblogic.xml.jaxp.RegistryDocumentBuilder.getFactoryFromEntities(RegistryDocumentBuilder.java:315)
at weblogic.xml.jaxp.RegistryDocumentBuilder.getCustomDocumentBuilderFactory(RegistryDocumentBuilder.java:227)
at weblogic.xml.jaxp.RegistryDocumentBuilder.getDocumentBuilder(RegistryDocumentBuilder.java:197)
at weblogic.xml.jaxp.RegistryDocumentBuilder.parse(RegistryDocumentBuilder.java:133)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:134)
at xmlwriter.xmlwriter.main(xmlwriter.java:15)
|
就是第一个问题,使用URI,你可以这样,指定协议:
String uri = "file:///" + new File( "links.xml" ).getAbsolutePath();
builder.parse(uri)
String uri = "file:///" + new File( "links.xml" ).getAbsolutePath();
builder.parse(uri)