黯夜旋风
2015-12-21 22:46
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)
看图,你少了一句
Java眼中的XML---文件读取
83199 学习 · 431 问题
相似问题