0

So in my app, I'm trying to fetch some custom objects I've made, and I'm getting this error:

Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
            at android.os.Handler.<init>(Handler.java:200)
            at android.os.Handler.<init>(Handler.java:114)
            at com.quickblox.core.server.HttpRequestRunnable$1.<init>(HttpRequestRunnable.java:40)
            at com.quickblox.core.server.HttpRequestRunnable.<init>(HttpRequestRunnable.java:40)
            at com.quickblox.core.server.ThreadPoolIntentService.execute(ThreadPoolIntentService.java:23)
            at com.quickblox.core.server.HttpRequestTask.execute(HttpRequestTask.java:29)
            at com.quickblox.core.rest.RestRequest.asyncRequestWithCallback(RestRequest.java:110)
            at com.quickblox.core.query.Query.performInBgAsyncWithDelegate(Query.java:115)
            at com.quickblox.core.query.Query.performAsyncWithCallback(Query.java:218)
            at com.quickblox.customobjects.QBCustomObjects.getObjects(QBCustomObjects.java:532)

Originially, I was calling the getObjects method from a separate thread I spawned to do the network communication, both because doing it on the UI thread seemed like a bad idea, and because when I tried to do it on the UI thread I got a NetworkCommunicationOnMainThread exception.

Since the separate thread didn't work, I put the request in an AsyncTask to see if that would help, and it didn't change anything.

The code for the request is below

        final QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();

        try {
            Log.i(classTag, "Attempting to get UserID");
            requestBuilder.eq("User_ID", ""+ QBAuth.getSession().getUserId());
        } catch (QBResponseException e) {
            Log.e(classTag, "Failed to get UserID for current user");
            e.printStackTrace();
            return null;

        }

        QBCustomObjects.getObjects("Listing", requestBuilder, new QBEntityCallbackImpl<ArrayList<QBCustomObject>>() { ...}

Any help would be greatly appreciated. Thanks!

1 Answer 1

0

This request works in a separate thread already

 QBCustomObjects.getObjects("Listing", requestBuilder, new QBEntityCallbackImpl<ArrayList<QBCustomObject>>() { ...}

so you don't need to wrap it

there is also a possibility to use 'sync' requests

2
  • If I put it on the UI thread however, I get a "NetworkOnMainThreadException". That was why I wrapped it in a separate thread.
    – AS7
    Jul 7, 2015 at 16:46
  • I guess you wrapped sync version of method, not this one
    – Rubycon
    Jul 21, 2015 at 7:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.