(Android) No Class Def Found Error for com.loopj.android.http.AsyncHttpClient

不羁岁月 提交于 2019-12-13 02:13:43

问题


I've added the following (http://loopj.com/android-async-http/) to my /libs folder and have also put it in the module settings as a library and ticked the export button. In the actual file there are no errors given that it can't find the class and when I do import com.loopj and so-forth it completes it for me and shows me the available options.

However, when I run it on my phone it gives the following errors:

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

and the extract of code (not complete obv as the URL is fake, but that shouldn't affect anything):

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

Would anyone know a solution to this problem?

Thank you very much, Daniel


回答1:


In Android Studio, you have to add your jar into the lib folder, add the dependency into the build.gradle file and call gradlew clean from console. The gradlew is in your project directory.

Check this thread for more details: Android Studio: Add jar as library?



来源:https://stackoverflow.com/questions/20327940/android-no-class-def-found-error-for-com-loopj-android-http-asynchttpclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!