Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception from call site #4 bootstrap method. Code doesn't work in Android studio, but works in Eclipse

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.

  1. Why HtmlUnit requires API 26, which is very high for technology now (only 19% of users), but it is just a web simulator?

  2. 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);
like image 357
Dmitry Kustarnikov Avatar asked Mar 07 '19 01:03

Dmitry Kustarnikov


1 Answers

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"
}
like image 173
Bhojaviya Sagar Avatar answered Oct 21 '22 20:10

Bhojaviya Sagar