Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android AsyncHttpClient, unable to find symbol class Header

I'm trying to create asynchronous rest call in Android using a library com.loopj.android.http.AsyncHttpClient however, i'm unable to implement AsyncHttpResponseHandler's overridden methods because Android Studio cannot find an appropriate import for Header class

How can I resolve the issue with the Header class not recognized by the Android Studio IDE?

 public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                // called when response HTTP status is "200 OK"
            }

I see that if I mouse over and click on the Header, I get the following message, but I don't know how to select one of the multiple choices in this menu (moving the mouse dismisses it)

enter image description here

like image 602
Alex Stone Avatar asked Apr 16 '15 20:04

Alex Stone


2 Answers

The answer by Alex is no longer valid as org.Apache.http is deprecated from API level 22.

Please replace all references of org.apache.http to cz.msebera.android.httpclient and use version 1.4.9 of loopj which includes the library.

For those who use gradle change your dependencies in build.gradle

dependencies {
  compile 'com.loopj.android:android-async-http:1.4.9'
}

Rebuild and then import cz.msebera.android.httpclient to use Header.

like image 103
Sharjeel Ahmed Avatar answered Oct 13 '22 22:10

Sharjeel Ahmed


By the time I typed this question, I found the answer, hopefully it will help you:

Press Option + enter on Mac when this popup is visible, then select import org.apache.http.Header; from the dropdown menu:

enter image description here

like image 44
Alex Stone Avatar answered Oct 13 '22 22:10

Alex Stone