handler.getSaxBooks().size() 出错 显示The method getSaxBooks() is undefined for the type SAXParserHandler明明定义了的 为什么还是显示没有这个方法呢?
package xml;
import java.io.IOException;
import java.util.logging.Handler;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import defaulthandler.SAXParserHandler;
public class SaxTest {
public static void main(String[] args) {
SAXParserFactory factory=SAXParserFactory.newInstance();
try {
SAXParser parse=factory.newSAXParser();
SAXParserHandler handler=new SAXParserHandler();
parse.parse("src/res/books.xml", handler);
System.out.println("共存储了"+handler.getSaxBooks().size()+"本书");
for (Books book : handler.getSaxBooks()) {
System.out.println("id: "+book.getId());
System.out.println("name: "+book.getName());
System.out.println("author: "+book.getAuthor());
System.out.println("language: "+book.getLanguage());
System.out.println("price: "+book.getPrice());
System.out.println("year: "+book.getYear());
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}