3

I am getting Current thread has not called Looper.prepare(). Forcing synchronous mode warning in logcat.So that I can't get into onsuccess response handler.

I referred this post.But it didn't worked for me.

Stacktrace:

01-19 22:52:30.683: W/AsyncHttpRH(23815): Current thread has not called Looper.prepare(). Forcing synchronous mode.

01-19 22:52:30.685: W/System.err(23815): java.lang.IllegalArgumentException: Synchronous ResponseHandler used in AsyncHttpClient. You should create your response handler in a looper thread or use SyncHttpClient instead.
01-19 22:52:30.686: W/System.err(23815):    at com.loopj.android.http.AsyncHttpClient.sendRequest(AsyncHttpClient.java:1493)
01-19 22:52:30.686: W/System.err(23815):    at com.loopj.android.http.AsyncHttpClient.get(AsyncHttpClient.java:1078)
01-19 22:52:30.686: W/System.err(23815):    at com.loopj.android.http.AsyncHttpClient.get(AsyncHttpClient.java:1052)
01-19 22:52:30.686: W/System.err(23815):    at agriya.talkr.localdb.RestClient.get(RestClient.java:29)
01-19 22:52:30.686: W/System.err(23815):    at agriya.talkr.localdb.ServerCallee.execute(ServerCallee.java:77)
01-19 22:52:30.686: W/System.err(23815):    at agriya.talkr.CreateGroup$synchronizeInBg.doInBackground(CreateGroup.java:213)
01-19 22:52:30.686: W/System.err(23815):    at agriya.talkr.CreateGroup$synchronizeInBg.doInBackground(CreateGroup.java:1)
01-19 22:52:30.686: W/System.err(23815):    at android.os.AsyncTask$2.call(AsyncTask.java:292)
01-19 22:52:30.686: W/System.err(23815):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-19 22:52:30.686: W/System.err(23815):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
01-19 22:52:30.686: W/System.err(23815):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-19 22:52:30.686: W/System.err(23815):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-19 22:52:30.686: W/System.err(23815):    at java.lang.Thread.run(Thread.java:818)

Below I have posted the code and pointed out the error line:

CreatGroup.java:

public class CreateGroup extends AppCompatActivity {

........
........

    @Override
        protected String doInBackground(String... params) {
          try {

       .......
      ServerCallee.execute(Constants.SERVER_CALL_newGroup, map); --->213th line
    } catch (JSONException e) {

        e.printStackTrace();
        return "1";

        }

ServerCallee.java:

public static void execute(final Constants _service, HashMap<String, String> params){

  ........
  ........


 RestClient.get(null, rqm, new JsonHttpResponseHandler(){  --->77th line

 ........
    @Override
    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
        System.out.println("onFailure - String: " + _service.toString());

        Log.e("fail 1", "Test");


     }
      .......(On Success response handler)

RestClient.java:

 public class RestClient {

          private static AsyncHttpClient client = new AsyncHttpClient();

      public static void get( String url,  RequestParams params, final JsonHttpResponseHandler responseHandler) {

              client.get(getAbsoluteUrl(url), params, responseHandler); -->29th line

          }

          public static void post(final String url, final RequestParams params, final JsonHttpResponseHandler responseHandler) {

             client.get(getAbsoluteUrl(url), params, responseHandler);

          }
    }
Community
  • 1
  • 1
Stephen
  • 9,899
  • 16
  • 90
  • 137

2 Answers2

7

Although you did not show it, it seems you call this from an AsyncTask. In this case you can use the SyncHttpClient as suggested by the error message.

Henry
  • 42,982
  • 7
  • 68
  • 84
0

In my case. Previously i was using

AsyncHttpClient client = new AsyncHttpClient();

Then i changed it to:

SyncHttpClient client = new SyncHttpClient();

client.get(CommentActivity.this, url, params , new JsonHttpResponseHandler()......
vijayraj34
  • 2,135
  • 26
  • 27