Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: CSS Error when using HTML Unit & Eclipse

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)

like image 960
Kgrover Avatar asked Nov 14 '22 12:11

Kgrover


1 Answers

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".

like image 95
Christian Kuetbach Avatar answered Nov 16 '22 03:11

Christian Kuetbach