2

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

6
  • Which IDE what you using? Commented Dec 2, 2013 at 12:18
  • Which api level you use... Commented Dec 2, 2013 at 12:18
  • have u added the jar file into the build path? Commented Dec 2, 2013 at 12:21
  • @coelho I am using android studio. Commented Dec 2, 2013 at 12:57
  • @harshit-rathi target API is 17 and min is 11. Commented Dec 2, 2013 at 12:58

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

2 Comments

That did it! I used Build -> Rebuild Project to emulate gradlew clean and it worked like a charm! Thank you very much
what about in Eclipse?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.