私は HtmlUnit (バージョン 2.9) を使用して、Web サイトからデータを取得する Android アプリを作成しています。コードは正常にコンパイルされますが、[ログイン] ボタンをクリックすると、WebUnit 変数の初期化に到達すると NoClassDefFoundError がスローされるため、クラッシュします。に瓶を追加しましたProject/lib
。
関連コード:
public void doLogin(View v) {
if (uname.getText().toString() == "" || pass.getText().toString() == "") {
makeToast("Missing at least one of the following: Username, Password");
Log.e("RobloxApp", "Missing a username and/or password");
return;
} else {
try {
WebClient client = new WebClient();
HtmlPage page = client.getPage(RbxRes.Urls.loginPage);
HtmlInput unameInput = (HtmlInput) page.getElementById(RbxRes.Elements.uNameId);
HtmlInput passInput = (HtmlInput) page.getElementById(RbxRes.Elements.passId);
HtmlButton loginBtn = (HtmlButton) page.getElementById(RbxRes.Elements.loginId);
unameInput.setTextContent(uname.getText().toString());
passInput.setTextContent(pass.getText().toString());
loginBtn.click();
} catch (Exception e) {
Log.e("RobloxApp", "The following error occurred while trying to login: " + e.getMessage());
makeToast("Error: Could not login");
return;
}
}
Logcat の出力:
07-14 04:38:46.357: E/AndroidRuntime(708): FATAL EXCEPTION: main
07-14 04:38:46.357: E/AndroidRuntime(708): java.lang.IllegalStateException: Could not execute method of the activity
07-14 04:38:46.357: E/AndroidRuntime(708): at android.view.View$1.onClick(View.java:3044)
07-14 04:38:46.357: E/AndroidRuntime(708): at android.view.View.performClick(View.java:3511)
07-14 04:38:46.357: E/AndroidRuntime(708): at android.view.View$PerformClick.run(View.java:14105)
07-14 04:38:46.357: E/AndroidRuntime(708): at android.os.Handler.handleCallback(Handler.java:605)
07-14 04:38:46.357: E/AndroidRuntime(708): at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 04:38:46.357: E/AndroidRuntime(708): at andr oid.os.Looper.loop(Looper.java:137)
07-14 04:38:46.357: E/AndroidRuntime(708): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-14 04:38:46.357: E/AndroidRuntime(708): at java.lang.reflect.Method.invokeNative(Native Method)
07-14 04:38:46.357: E/AndroidRuntime(708): at java.lang.reflect.Method.invoke(Method.java:511)
07-14 04:38:46.357: E/AndroidRuntime(708): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-14 04:38:46.357: E/AndroidRuntime(708): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-14 04:38:46.357: E/AndroidRuntime(708): at dalvik.system.NativeStart.main(Native Method)
07-14 04:38:46.357: E/AndroidRuntime(708): Caused by: java.lang.reflect.InvocationTargetException
07-14 04:38:46.357: E/AndroidRuntime(708): at java.lang.reflect.Method.invokeNative(Native Method)
07-14 04:38:46.357: E/AndroidRuntime(708): at java.lang.reflect.Method.invoke(Method.java:511)
07-14 04:38:46.357: E/AndroidRuntime(708): at android.view.View$1.onClick(View.java:3039)
07-14 04:38:46.357: E/AndroidRuntime(708): ... 11 more
07-14 04:38:46.357: E/AndroidRuntime(708): Caused by: java.lang.NoClassDefFoundError: com.gargoylesoftware.htmlunit.WebClient
07-14 04:38:46.357: E/AndroidRuntime(708): at com rbx.robloxapp.Login.doLogin(Login.java:46)
07-14 04:38:46.357: E/AndroidRuntime(708): ... 14 more