日期:2014-05-20  浏览次数:20747 次

求救,JDOM使用问题
SAXBuilder   builder   =   new   SAXBuilder(false);
Document   doc   =   builder.build(configURI);
configURI是String类型
运行到Document   doc   =   builder.build(configURI);就出错

org.jdom.JDOMException:   Error   in   building:   Class   org.jdom.input.SAXBuilder   can   n
ot   access   a   member   of   class   gnu.xml.aelfred2.JAXPFactory$JaxpParser   with   modifie
rs   "public "
                at   org.jdom.input.SAXBuilder.build(SAXBuilder.java:411)
                at   org.jdom.input.SAXBuilder.build(SAXBuilder.java:464)
                at   org.jdom.input.SAXBuilder.build(SAXBuilder.java:445)
                at   JDomParse. <init> (JDomParse.java:16)
                at   JDomParse.main(JDomParse.java:40)
Root   cause:   java.lang.IllegalAccessException:   Class   org.jdom.input.SAXBuilder   ca
n   not   access   a   member   of   class   gnu.xml.aelfred2.JAXPFactory$JaxpParser   with   modi
fiers   "public "
                at   sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
                at   java.lang.reflect.Method.invoke(Method.java:578)
                at   org.jdom.input.SAXBuilder.build(SAXBuilder.java:295)
                at   org.jdom.input.SAXBuilder.build(SAXBuilder.java:464)
                at   org.jdom.input.SAXBuilder.build(SAXBuilder.java:445)
                at   JDomParse. <init> (JDomParse.java:16)
                at   JDomParse.main(JDomParse.java:40)

------解决方案--------------------
configURI是什么啊,这个String参数应该是一个xml文件的路径吧
SAXBuilder sb = new SAXBuilder();
Document doc = null;
try {
doc = sb.build( "c:\\test.xml ");
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
------解决方案--------------------
这样改试试
Document doc = builder.build(new File(configURI));

------解决方案--------------------

try {

   SAXBuilder builder = new SAXBuilder();
   Document doc = builder.build(new File(configURI));
   Element foo = doc.getRootElement();
   List allChildren = foo.getChildren();
   for(int i=0;i<allChildren.size();i++) {
    System.out.print(((Element)allChildren.get(i)).getChild( "节点名字 ").getText());  
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
------解决方案--------------------
Document doc = builder.build(new File(filename));
------解决方案--------------------
我想你要用的应该是
Document doc = builder.build(new URL(configURI));

在java里URL可不是String类型,build(String)的方法接受的是xml原码,build(URL)才会自动适用网络获取源码,这个问题我也碰到过,不过是很久以前了。