5

I am using Html Unit to go to a webpage, fill in some forms, and click a button to get to the next webpage. That new webpage, (called newPage in my code) is what I'm extracting the html source from.

This method works perfectly in Netbeans (although it does give an excessive amount of warnings)

import org.jsoup.Jsoup;

/* Regular (textview, button, etc) imports */

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;


        String username = "USERNAME", school = "SCHOOL", userpassword = "PASSWORD";
        HtmlElement loginName = null;
        HtmlElement password = null;
        //HtmlPage newPage;
        HtmlAnchor anchorByHref = null;
        try {
            WebClient webClient = new WebClient();
            final HtmlPage page = webClient
                    .getPage("https://cupertino.schoolloop.com/portal/login?d=x&return_url=1325402408153");
            loginName = page.getElementByName("login_name");
            password = page.getElementByName("password");
            loginName.setTextContent(username);
            loginName.setAttribute("value", username);
            password.setAttribute("value", userpassword);
            password.setTextContent(userpassword);
            anchorByHref = page
                    .getAnchorByHref("javascript:document.form.event_override.value='login';document.form.submit();");
            HtmlPage newPage = anchorByHref.click();

            webClient.waitForBackgroundJavaScript(10000);
            String html = newPage.getWebResponse().getContentAsString();


            message2.setText(html);
        } catch (Exception e) {
            e.printStackTrace();

        }


}

However, in Eclipse running Android, it says

01-02 17:38:54.099: E/dalvikvm(23163): Could not find class 'org.w3c.dom.css.CSSCharsetRule', referenced from method com.gargoylesoftware.htmlunit.javascript.host.css.CSSCharsetRule.getCharsetRule

in the logcat.

Also, it doesn't set message2's text as the html I want although when I try this in Netbeans and print "html" it does in fact print the full html source of the page!

In summary, there are 2 Problems. Eclipse is not successfully getting the html, and it is giving an error saying could not find CSSCharsetRule class. I think I have imported the appropriate .jar for this, but I am not certain because HTML Unit comes with around 15 .jars and I cannot import them all otherwise the application has trouble in emulator and phone.

I have figured out that the error was due to not importing xml-apis-1.3.04.jar (which was imported in the Netbeans Project).

However, now I encounter a

"Conversion to Dalvik Format Failed with Error 1"

Error.

Is it possible that any of the problems would cause the Null value of html, and how do I fix the Dalvik Conversion Error?

.jar Eclipse(too many makes app heavy, and including xml-apis causes Dalvik Error)

Jar files in Netbeans (working)

Kgrover
  • 2,106
  • 2
  • 36
  • 54
  • import meaning to add them to the build path in Eclipse*. Also, adding JUnit as one of the jars helped. – Kgrover Jan 03 '12 at 02:27

1 Answers1

1

I think you have a problem with you classpath within eclipse:

Could not find class 'org.w3c.dom.css.CSSCharsetRule'

Do you have all Jars included to the buildpath?

Conversion to Dalvik Format Failed with Error 1

This tells me, that one of your *.class can't be convertet into a *dex-file

Maybe you have two jar-files with the same class inside:

I solved the problem.

It seems that I have two jars on my buildpath that include the same package and classes.

"Conversion to Dalvik format failed with error 1" on external JAR

edit To find duplicate Classes, extract all jars with your favourite unzip-tool and wait for "This file aready exists".

Community
  • 1
  • 1
Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79
  • How do I figure out which .jar files conflict? Also, do you think this is the reason why html variable would return null? (No content there) again, if I import *all* jars in Netbeans, it works. If I import all jars in Eclipse, the application becomes too heavy. I have edited my answer with pictures of the jars imported in each IDE if that will help. – Kgrover Jan 05 '12 at 16:23
  • also, I think the addition of the xml-apis jar is what *has* the class 'org.w3c.dom.css.CSSCharsetRule' but that is what causes the Dalvik Error. – Kgrover Jan 05 '12 at 16:28
  • Thanks for the JARS, please expand the eclipse ADT and Android ClassPath Container. Maybe you have duplicated APIs there. – Christian Kuetbach Jan 06 '12 at 07:50
  • I do not think those are the conflicting jars as I said, the Dalvik Error occurs when I add xml-apis.jar. I will try unzipping them and let you know. – Kgrover Jan 07 '12 at 02:06