gpt4 book ai didi

java - Android:使用 HTML Unit 和 Eclipse 时出现 CSS 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:51 24 4
gpt4 key购买 nike

我正在使用 Html Unit 转到一个网页,填写一些表格,然后单击一个按钮进入下一个网页。这个新网页(在我的代码中称为 newPage)是我从中提取 html 源代码的地方。

此方法在 Netbeans 中非常有效(尽管它确实给出了过多的警告)

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();

}


}

但是,在运行 Android 的 Eclipse 中,它说

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

在日志中。

此外,它没有将 message2 的文本设置为我想要的 html 尽管当我在 Netbeans 中尝试此操作并打印“html”时,它实际上打印了页面的完整 html 源代码!

总结起来,有2个问题。 Eclipse 没有成功获取 html,它给出了一个错误,提示找不到 CSSCharsetRule 类。我想我已经为此导入了适当的 .jar,但我不确定,因为 HTML Unit 附带了大约 15 个 .jar,我无法导入它们,否则应用程序在模拟器和手机中会出现问题。

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

但是,现在我遇到了一个

"Conversion to Dalvik Format Failed with Error 1"

错误。

是否有任何问题会导致 html 的 Null 值,以及如何修复 Dalvik 转换错误?

.jar Eclipse(太多会使应用程序变重,包含 xml-apis 会导致 Dalvik 错误)

Netbeans 中的 Jar 文件(工作)

最佳答案

我认为您在 eclipse 中的类路径有问题:

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

您是否已将所有 Jar 包含到构建路径中?

Conversion to Dalvik Format Failed with Error 1

这告诉我,您的 *.class 之一不能转换成 *dex 文件

也许您有两个内部类相同的 jar 文件:

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

编辑要查找重复的类,请使用您最喜欢的解压缩工具提取所有 jar 并等待“此文件已存在”。

关于java - Android:使用 HTML Unit 和 Eclipse 时出现 CSS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8707296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com