输出BookList的时候空指针异常了~~~
for(Book book : handler.getBookList()){
System.out.println(book.getId() + " ");
System.out.println(book.getAuthor() + " ");
System.out.println(book.getName() + " " + book.getLanguage() + " ");
System.out.println(book.getPrice() + " " + book.getYear() + " ");
System.out.println("-----finish-----");
}
//handler内容
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
super.endElement(uri, localName, qName);
if(qName.equals("book")){
book = null;
System.out.println("本书完");
}else if(qName.equals("name")){
book.setName(value);
}else if(qName.equals("author")){
book.setAuthor(value);
}else if(qName.equals("year")){
book.setYear(value);
}else if(qName.equals("price")){
book.setPrice(value);
}else if(qName.equals("language")){
book.setLanguage(value);
}
}
//结果
Exception in thread "main" java.lang.NullPointerException
at com.imooc.test.SAXtest.main(SAXtest.java:27)