使用HtmlUnit WebClient.getPage时出现多个错误



我是第一次尝试HtmlUnit。我正在Linux Mint 17.1上进行开发。我也是Java的新手。我安装了jenkins-htmlunit,我的java环境是java-7-openjdk-amd64。

我发现了以下示例:

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
public class myClient {
public static void main(String[] args) throws Exception {
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
System.out.println(page.asXml());
}    
}

但是,在执行以下shell命令后:

javac-cp"/usr/share/java/"myClient.java导出CLASSPATH=$CLASSPATH:/usr/share/java/java myClient

我得到以下错误:

线程"main"java.lang.NullPointerException在com.gargoylesoftware.htmlmunit.javascript.SimpleScriptable.getPrototype(SimpleScriptable.java:247)在com.gargoylesoftware.htmlmunit.javascript.SimpleScriptable.makeScriptableFor(SimpleScriptable.java:217)在com.gargoylesoftware.htmlmunit.html.DomNode.getScriptObject(DomNode.java:790)在com.gargoylesoftware.htmlmunit.html.HtmlScript.setAndExecuteReadyState(HtmlScript.java:457)在com.gargoylesoftware.htmlmunit.html.HtmlScript$1.execute(HtmlScript.java:212)在com.gargoylesoftware.htmlmunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:238)在com.gargoylesoftware.htmlmunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:699)网址:org.apache.xerces.parsers.AbstractSAXParser.endElement(未知来源)com.gargoylesoftware.htmlmunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:657)在org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancir.java:1170)在org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancir.java:1072)在org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)在org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:330)在org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3116)在org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2083)网址:org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:918)在org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)在org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)网址:org.apache.xerces.parsers.XMLParser.parse(未知来源)com.gargoylesoftware.htmlmunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:901)在com.gargoylesoftware.htmlmunit.html.HTMLParser.parse(HTMLParser.java:350)在com.gargoylesoftware.htmlmunit.html.HTMLParser.parseHtml(HTMLParser.java:304)在com.gargoylesoftware.htmlmunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:134)在com.gargoylesoftware.htmlmunit.DefaultPageCreator.createPage(DefaultPageCreator.java:101)在com.gargoylesoftware.htmlmunit.WebClient.loadWebResponseInto(WebClient.java:449)在com.gargoylesoftware.htmlmunit.WebClient.getPage(WebClient.java:332)在com.gargoylesoftware.htmlmunit.WebClient.getPage(WebClient.java:389)在com.gargoylesoftware.htmlmunit.WebClient.getPage(WebClient.java:374)在myClient.main(myClient.java:8)

当使用最新的快照构建时,这对我来说很好。请切换到最新的快照(此页面上有一些有用的详细信息http://htmlunit.sourceforge.net/gettingLatestCode.html)。如果您没有特殊需求,最好使用最新的快照构建,因为我们会根据用户反馈进行定期修复。

相关内容

  • 没有找到相关文章

最新更新