# Error when using Java REST Client in Android Studio

**URL:** https://discuss.elastic.co/t/error-when-using-java-rest-client-in-android-studio/180904
**Category:** Elasticsearch
**Created:** [May 14, 2019, 1:39am UTC](https://discuss.elastic.co/t/error-when-using-java-rest-client-in-android-studio/180904 "2019-05-14T01:39:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fmisso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fmisso/32/50267_2.png) [@fmisso](https://discuss.elastic.co/u/fmisso)
#### Post date: [May 14, 2019, 1:39am UTC](https://discuss.elastic.co/t/error-when-using-java-rest-client-in-android-studio/180904/1 "2019-05-14T01:39:31Z")

</div>

Hello,  
I'm trying your Java REST client API in Android Studio.  
But i have this error

> Caused by: java.lang.NoSuchFieldError: No field INSTANCE of type Lorg/apache/http/message/BasicLineFormatter; in class Lorg/apache/http/message/BasicLineFormatter;

Impossible to find a solution...  
I try to exclude httpclient module in my gradle file,

> implementation ('org.elasticsearch.client:elasticsearch-rest-client:7.0.1'){  
> exclude module: 'httpclient'  
> exclude module: 'httpcore-nio'  
> exclude module: 'httpcore'  
> }

But nothing, it doesn't work.  
Could you help me, please !  
Thanks

---

<div class="post-metadata">

### Author: ![emskypl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emskypl/32/45057_2.png) [@emskypl](https://discuss.elastic.co/u/emskypl)
#### Post date: [May 21, 2019, 7:14pm UTC](https://discuss.elastic.co/t/error-when-using-java-rest-client-in-android-studio/180904/2 "2019-05-21T19:14:26Z")

</div>

I have the same problem. I was thinking about Java API but elastic say it's deprecated. Can someone help? Can we use other http client?

---

<div class="post-metadata">

### Author: ![fmisso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fmisso/32/50267_2.png) [@fmisso](https://discuss.elastic.co/u/fmisso)
#### Post date: [May 21, 2019, 9:44pm UTC](https://discuss.elastic.co/t/error-when-using-java-rest-client-in-android-studio/180904/3 "2019-05-21T21:44:25Z")

</div>

I did not find a solution despite hours of research. Too bad the support is not more active. I took the solution with an AsyncHttpClient object

public class DAOElastic extends JsonHttpResponseHandler{  
private String URL;  
private AsyncHttpClient client ;  
private boolean error;

```
public DAOElastic(){
    this.URL = "http://192.168.1.154:9200/";
    this.client = new AsyncHttpClient();
    this.error = false;
}

public void get(String url, RequestParams params) {
    this.client.get((this.URL+url), params, this);
}

public void post(String url, RequestParams params) {
    this.client.post((this.URL+url), params, this);
}

@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
    // If the response is JSONObject instead of expected JSONArray
    this.error = false;
    this.deserialiseMedicaments(response);
}

@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
    //Log.i(CLASS_NAME, "onSuccess: " + response.toString());

}

@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
    super.onFailure(statusCode, headers, responseString, throwable);
    // called when response HTTP status is "4XX" (eg. 401, 403, 404)
    this.error = true;
}

@Override
public void onRetry(int retryNo) {
    Log.i("Test", "onRetry " + retryNo);
    // called when request is retried
}

@Override
public ArrayList<Object> getObjects() {
    this.get("myobj/_search", null);
    if (this.error == false){
        return null;
    }
    else{
        return null;
    }
}

```

}

Not the better solution, but it's work.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 18, 2019, 9:54pm UTC](https://discuss.elastic.co/t/error-when-using-java-rest-client-in-android-studio/180904/4 "2019-06-18T21:54:17Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
