解析与JSOUP强制关闭了NullPointerException异常标记 [英] Parsing a tag with JSOUP force closing for nullPointerException
本文介绍了解析与JSOUP强制关闭了NullPointerException异常标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当试图解析链接
http://pc.gamespy.com/pc/bastion/
Element overview = doc.select("div#object-overview").last();
Element paragraph = overview.select("p").last();
它给了我一个NullPointerException异常。
It gives me a nullpointerexception.
和也与此一
http://wii.gamespy.com/wii/jerry -rice-nitus狗足球/
在这里给空指针
Element featureList = doc.select("div.callout-box").last();
featuresText.setText("FEATURE: " + featureList.text());
这是为什么?我想找回的概述部分。它适用于所有其他项目。
Why is this? I am trying to retrieve the overview section. it works for all the other items.
推荐答案
根据 http://jsoup.org/apidocs / ,Jsoup抛出 NullPointerException异常
如果该参数为null。在相当。选择(#DIV对象概述)
返回换句话说null或。选择(P)
。首先尝试检查空,然后用。去年()
方法类似这样
According to http://jsoup.org/apidocs/, Jsoup throws NullPointerException
if the argument is null. In other words rather .select("div#object-overview")
returns null or .select("p")
. Try to check for null first, then use .last()
method like this
Elements overviews = doc.select("div#object-overview");
if(!overview==null){
Element overview = overviews.last();
}
等
这篇关于解析与JSOUP强制关闭了NullPointerException异常标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文