java - 调用站点 #4 引导方法的异常。代码在 Android Studio 中不起作用,但在 Eclipse 中起作用
问题描述
我正在编写代码以使用 HtmlUnit 登录网站。它一直在 Eclipse 中工作,但现在我决定将它移到 Android Studio 中,在应用程序中使用它。我有 2 个问题。
为什么 HtmlUnit 需要 API 26,这对于现在的技术来说已经很高了(只有 19% 的用户),但它只是一个 web 模拟器?
为什么在创建 webClient 时出现此错误?我的例外是:
java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
at com.gargoylesoftware.htmlunit.WebClient.addDefaultHeaders(WebClient.java:1496)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1392)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1321)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:394)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
at notas.com.mistarapp.Student.login(Student.java:65)
这是我正在经历的代码。所有内容均已导入,并且未突出显示为错误。这是我的代码:
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
HtmlPage firstPage = webClient.getPage(link);
// waitForBackgroundJavaScript has to be called after every action
webClient.waitForBackgroundJavaScript(100);
System.out.println("Access to the login page is made.");
System.out.println("-------------------------------------------------------------------------------");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
HtmlForm form = firstPage.getFormByName("loginform");
线上出现错误:
HtmlPage firstPage = webClient.getPage(link);
解决方案
I have fixed this issue by adding Java8 to app-level build.gradle in android section.
Java 8 in your builds to function as of version 9.0.0 and newer. You can learn more about how to enable this at https://developer.android.com/studio/write/java8-support.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
推荐阅读
- google-cloud-platform - 在 GCP 中加载 SQL 失败
- vb6 - 以编程方式将列注释添加到 Microsoft Access-97 数据库
- c# - 参考 Azure Functions 中的 Cosmos DB nuget 包
- c# - WPF 效果防止纹理重新加载
- javascript - 动态添加元素上的每个循环的单击事件 javascript / jquery
- android - 获取用户电子邮件 firebase 身份验证
- ssl - 内部代理是否需要 HTTPS?
- oracle-apex - 在 Oracle APEX 中插入静态数据以及数据加载向导实用程序
- jquery - jQuery插件无法识别的表达式:[object Object]
- php - AngularJs - PHP POST 问题