1

I'm using example code from the Apache documentation, shown here:

        final WebClient webClient = new WebClient();

    // Get the first page
    final HtmlPage page1 = webClient.getPage("http://some_url");

    // Get the form that we are dealing with and within that form, 
    // find the submit button and the field that we want to change.
    final HtmlForm form = page1.getFormByName("myform");

    final HtmlSubmitInput button = form.getInputByName("submitbutton");
    final HtmlTextInput textField = form.getInputByName("userid");

    // Change the value of the text field
    textField.setValueAttribute("root");

    // Now submit the form by clicking the button and get back the second page.
    final HtmlPage page2 = button.click();

    webClient.closeAllWindows();

I get errors from WebClient, HtmlPage, HtmlForm... basically, everything that should be imported from Apache, just isn't.

I've followed a bunch of guides on the web directing me on hwo to add external jars to my build path, and as far as I can tell, everything is set-up correctly. I've tried Cleaning the project, restarting Eclipse, closing/opening the project, etc. Nothing seems to work.

For reference, I downloaded the .JARs from this website: http://hc.apache.org/.

My import statements:

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

My error message:

[2014-06-23 12:43:55 - CampusHappenings] Dx 1 error; aborting [2014-06-23 12:43:55 - CampusHappenings] Conversion to Dalvik format failed with error 1

The entirety of the stacktrace is much too long to copy, but it's something to do with the htmlunit JARs themselves, not with my code. They all look something like this:

Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (org.apache.xalan.lib.sql.SecuritySupport12$4) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format.

Thoughts? I'm so confused.

Miles Peele
  • 325
  • 5
  • 15

1 Answers1

1

Since I've seen Dalvik in the error log, I'm assuming that you're writing your code for Android but try to use a common version of Apache's HttpClient that might not be compatible with Android. You should really check this Apache's document and try their 4.3 port specifically aimed for Android.

https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

HttpClient for Android jar can be found here: http://search.maven.org/remotecontent?filepath=org/apache/httpcomponents/httpclient-android/4.3.3/httpclient-android-4.3.3.jar

Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
  • Didn't even realize there was a separate thing for Android. I'll check it out, thanks. I'm not seeing an JARs for this, which is how I'm accustomed to adding stuff to Eclipse, and I've never heard of Maven. How would I integrate this client into my project? – Miles Peele Jun 23 '14 at 18:29
  • I hate Androiders for their opportunistic approach to Java and violating its major principle "write once, run everywhere", but there is not much I can do about it, except ranting :) – Oleg Gryb Jun 23 '14 at 18:33
  • If you're not using maven, just try to download the jar from here: http://search.maven.org/#search|ga|1|a%3A%22httpclient-android%22 You'll need to click on 'jar' link to start the download. – Oleg Gryb Jun 23 '14 at 19:11
  • Understood, thanks. I ended up scrapping using Apache HTTP for this anyway, as apparently it's not recommended for Android developers. Thanks for your help though. – Miles Peele Jun 24 '14 at 14:05