我在Eclipse中使用Jsoup时遇到了这个问题。我附加了以下jar文件: jsoup 1.7.2.jar jsoup 1.7.2.javadoc.jar jsoup 1.7.2.sources.jar 我已经将这些jar文件作为外部jar文件添加到配置路径中,并且已经将它们链接到我存储文件的C:\ USERS驱动器。该程序没有错误,但当我运行它时,我得到这行NullPointerException错误“Element gameElement = firstLottoRow.child(1);”或者像这样使用Jsoup从URL解析HTML的任何其他代码行。 我得到的“元素既没有附加源代码也没有附加Javadoc,因此没有Javadoc可以被找到”,代码行为:“元素tbody = table.getElementsByTag(”tbody“)。first();”此元素既没有附加源代码也没有附加Javadoc,因此也没有找到Javadoc
我是否正确处理链接到jsoup jar文件的配置路径,或者任何人都可以提出我做错了什么? 非常感谢您的帮助!
这里是Jsoup代码:
private LotteryDraw extractLotteryDraw(String html) {
LotteryDraw lotteryDraw = new LotteryDraw();
Document doc = Jsoup.parse(html);
Elements elements = doc.getElementsByClass("drawhistory");
//System.out.println(elements.toString());
Element table = elements.first();
Element tbody = table.getElementsByTag("tbody").first();
Element firstLottoRow = tbody.getElementsByClass("lottorow").first();
Element dateElement = firstLottoRow.child(0);
System.out.println(dateElement.text());
Element gameElement = firstLottoRow.child(1);
System.out.println(gameElement.text());
Element noElement = firstLottoRow.child(2);
System.out.println(noElement.text());
String[] split = noElement.text().split(" - ");
int[] numbers = new int[split.length];
int i = 0;
for (String strNo : split) {
numbers[i] = Integer.valueOf(strNo);
i++;
}
lotteryDraw.setNumbers(numbers);
Log.v("DEBUG", "the value of numbers is " + numbers);
Element bonusElement = firstLottoRow.child(3);
Integer bonusBall = Integer.valueOf(bonusElement.text());
lotteryDraw.setBonusBall(bonusBall);
Log.v("DEBUG", "the value of numbers is " + numbers);
return lotteryDraw;
对不起,所以这还没有工作。我去了1.7.2的jsoup。 javadoc.jar文件在引用的libs下,右键点击它将我带到一个屏幕,标题为Java Source Attachment,要求选择我选择的外部位置(文件夹/ jar/zip)的位置,因为我已经将它存储在C:\ drive中。当我选择工作区位置时,我无法找到它,因为它不在那里。我究竟做错了什么? –
单击“外部文件...”并选择要附加的罐子。 – Henry
我做的jar是在libs文件夹中,但它仍然不能识别 –