顯示運行出錯
package cn.iast.dom4j;
import java.io.Reader;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class dom4j {
public static void main(String[] args) {
try {
run1();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void run1() throws Exception{
SAXReader reader = new SAXReader();
Document document = reader.read("src/book2.xml");
Element root = document.getRootElement();
List<Element> books = root.elements("書");
Element book2 = books.get(1);
Element author2 = book2.element("作者");
System.out.println(author2.getText());
}
你的book2.xml難道不是放在cn.iast.add包下面?並不在src的直屬目錄下面