为了账号安全,请及时绑定邮箱和手机立即绑定

输出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)


正在回答

1 回答

http://img1.sycdn.imooc.com//567822bf000130fd03560150.jpg看图,你少了一句


1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

输出BookList的时候空指针异常了~~~

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信