(Android)com.loopj.android.http.AsyncHttpClient没有Class Def Found错误

时间:2013-12-02 12:07:44

标签: java android http android-studio noclassdeffounderror

我已将以下(http://loopj.com/android-async-http/)添加到我的/ libs文件夹中,并将其作为库放入模块设置中并勾选导出按钮。在实际文件中没有错误,因为它找不到类,当我导入com.loopj时,它会为我完成它并向我显示可用的选项。

但是,当我在手机上运行它时会出现以下错误:

12-02 23:00:08.943    8209-8209/mobi.vassilev.beam E/dalvikvm﹕ Could not find class   'com.loopj.android.http.AsyncHttpClient', referenced from method mobi.vassilev.beam.GoogleLoginActivity.requestAPIKeyFromOAuthToken
12-02 23:00:09.183    8209-8209/mobi.vassilev.beam E/﹕ file /data/data/com.nvidia.NvCPLSvc/files/driverlist.txt: not found!
12-02 23:00:10.453    8382-8382/? E/ObjectHelper﹕ Can't find method:setCompatibilityInfo
12-02 23:00:10.598    8209-8209/mobi.vassilev.beam E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.loopj.android.http.AsyncHttpClient
            at mobi.vassilev.beam.GoogleLoginActivity.requestAPIKeyFromOAuthToken(GoogleLoginActivity.java:118)
            at mobi.vassilev.beam.GoogleLoginActivity.access$200(GoogleLoginActivity.java:24)
            at mobi.vassilev.beam.GoogleLoginActivity$OnTokenAcquired.run(GoogleLoginActivity.java:105)
            at android.accounts.AccountManager$11.run(AccountManager.java:1335)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:158)
            at android.app.ActivityThread.main(ActivityThread.java:5751)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
            at dalvik.system.NativeStart.main(Native Method)
12-02 23:00:10.633      513-548/? E/EmbeddedLogger﹕ App crashed! Process: mobi.vassilev.beam

和代码的提取(不完整的obv,因为URL是假的,但不应该影响任何东西):

  private void requestAPIKeyFromOAuthToken(String token) {
        AsyncHttpClient client = new AsyncHttpClient();        // <-- this is line 118
        RequestParams params = new RequestParams("token", token);

        client.post("https://myrailsapp.com/api/v1/auth/verify", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(String response) {
                Log.w("OAUTH", "Got API key from server: " + response);
                finish();
            }

            @Override
            public void onFailure(Throwable e) {
                Log.w("OAUTH", "Error getting API key");
                Toast.makeText(getApplicationContext(), R.string.connection_error_message, Toast.LENGTH_LONG).show();

                e.printStackTrace();
            }
        });
    }

有人知道这个问题的解决方案吗?

非常感谢, 丹尼尔

1 个答案:

答案 0 :(得分:0)

在Android Studio中,您必须将jar添加到lib文件夹中,将依赖项添加到build.gradle文件中并从控制台调用gradlew clean。 gradlew位于项目目录中。

查看此主题以获取更多详细信息:Android Studio: Add jar as library?