I am writing a code to login onto a website using HtmlUnit. It has been working in eclipse, but now I decided to move it into Android studio use it in an app. I have 2 questions.
Why HtmlUnit requires API 26, which is very high for technology now (only 19% of users), but it is just a web simulator?
Why am getting this error while creating a webClient? My exception is:
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)
And this is my code I am going through. Everything is imported, and is not highlighted as an error. Here is my code:
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");
error occures on the line:
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With