请大神解决我的异常
跟着老师一起打的。对过了
package com.imooc.jdomtest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
public class JDOMTest {
public static void main(String[] args) {
//进行对books.xml文件的JDOM解析
//1.创建一个SAXBuilder对象
SAXBuilder saxBuilder = new SAXBuilder();
InputStream in;
try {
//2.创建一个输入流,将XML文件加载到输入流
in = new FileInputStream("src/res/books.xml");
//3.通过saxBuilder的build方法,将输入流加载到saxBuilder中
Document document = saxBuilder.build(in);
//4.通过document对象获取xml文件的根节点
Element rootElement = document.getRootElement();
//5.获取根节点下的子节点的List集合
List<Element> bookList = rootElement.getChildren();
//6.继续进行解析
for (Element book : bookList) {
System.out.println("开始解析第"+(bookList.indexOf(book)+1)+"本书=========");
System.out.println("结束解析第"+(bookList.indexOf(book)+1)+"本书=========");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
异常如下:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom2/JDOMException
Caused by: java.lang.ClassNotFoundException: org.jdom2.JDOMException