I have the need to use loopj's SyncHttpClient in a couple areas. When I use AsyncHttpClient, the request returns successfully. When I use the SyncHttpClient as shown in the accepted answer here: How to use loopJ SyncHttpClient for synchronous calls?, I hit a breakpoint in onFailure
. The statusCode is 0, the errorResponse is null, and throwable is java.io.IOException: Unhandled exception: null.
Here is the relevant code. Again when I use Async it works fine:
buttonTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// AsyncHttpClient httpClient = new AsyncHttpClient();
SyncHttpClient httpClient = new SyncHttpClient();
httpClient.get("http://10.0.1.6:3000/home/test_endpoint", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
String stringResponse = response.toString();
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
String error = errorResponse.toString();
}
});
String temp = "got here";
}
});
I'm using compile 'com.loopj.android:android-async-http:1.4.9'