我正在尝试使用HtmlUnit登录网站。我正在使用以下代码登录:
try (final WebClient webClient = new WebClient()) {
// try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
final HtmlPage firstPage = webClient.getPage(link);
// waitForBackgroundJavaScript has to be called after every action
webClient.waitForBackgroundJavaScript(100);
最后一个HtmlPage firstPage = webClient.getPage(link);我得到一个错误。为什么会发生?这是我收到的错误日志:
java.lang.BootstrapMethodError:调用站点#4引导程序方法异常 在com.gargoylesoftware.htmlunit.WebClient.addDefaultHeaders(WebClient.java:1496) 在com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1392) 在com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1321) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448) 在notas.com.mistarapp.Student.login(Student.java:69) 在notas.com.mistarapp.student_loading.onCreate(student_loading.java:26) 在android.app.Activity.performCreate(Activity.java:7136) 在android.app.Activity.performCreate(Activity.java:7127) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 在android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 在android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1808) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:193) 在android.app.ActivityThread.main(ActivityThread.java:6669) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 原因:java.lang.ClassCastException:Bootstrap方法返回null 在com.gargoylesoftware.htmlunit.WebClient.addDefaultHeaders(WebClient.java:1496) 在com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1392) 在com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1321) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466) 在com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448) 在notas.com.mistarapp.Student.login(Student.java:69) 在notas.com.mistarapp.student_loading.onCreate(student_loading.java:26) 在android.app.Activity.performCreate(Activity.java:7136) 在android.app.Activity.performCreate(Activity.java:7127) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 在android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 在android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1808) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:193) 在android.app.ActivityThread.main(ActivityThread.java:6669) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2019-03-07 21:14:15.438 1928-2001 /? E / InputDispatcher:通道'bdcf4f3吐司(服务器)'〜通道无法恢复,将被废弃!
这只发生在Android Studio中,我在最初编写代码的Eclipse中对其进行了测试,但是当我转移到Android Studio时,它不起作用。