2017-04-20 84 views
2

這裏使用GETPAGE當是我用簡單的代碼片段:ClassCastException異常試圖的HtmlUnit

final WebClient client = new WebClient(); 
final HtmlPage page = client.getPage("http://www.muthead.com/packs/simulator/12-tokearmy-pack"); 

這是給我下面的:

Exception in thread "main" ======= EXCEPTION START ======== 
Exception class=[java.lang.ClassCastException] 
com.gargoylesoftware.htmlunit.ScriptException: com.gargoylesoftware.htmlunit.javascript.host.html.HTMLAnchorElement cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlElement 
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:921) 
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628) 
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515) 
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:852) 
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:824) 
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:216) 
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:258) 
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:322) 
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.fireEvent(EventTarget.java:206) 
    at com.gargoylesoftware.htmlunit.html.DomElement$2.run(DomElement.java:1190) 
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628) 
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515) 
    at com.gargoylesoftware.htmlunit.html.DomElement.fireEvent(DomElement.java:1195) 
    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1198) 
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:238) 
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:519) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:386) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:304) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:451) 
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:436) 
    at Runner.main(Runner.java:26) 
== CALLING JAVASCRIPT == 
    function (l) { 
     k.call(i, l); 
    } 
======= EXCEPTION END ======== 

奇怪的是,如果我切換出的鏈接http://google.com,一切工作正常。這是否意味着我試圖鏈接到的網頁有問題? (儘管它是一個有效的鏈接)

回答

1

這是最近修復int 2.27-SNAPSHOT,你的測試用例現在通過與latest build(登錄爲'客人')。

請相應更新。