Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

facebook, android java.lang.IllegalStateException: Cannot execute task: the task is already running

After login I can I can make FB queries. After few minutes (played game) Facebook requests fail exception:

java.lang.IllegalStateException: Cannot execute task: the task is already running

It fails when I call

        Request.executeMeRequestAsync(Session.getActiveSession(),
                new Request.GraphUserCallback() {...

        Request.executeGraphPathRequestAsync(Session.getActiveSession(),
                "me/apprequests", new Request.Callback() {...

        Request request = new Request(session, "me/apprequests", null,
                    null, new Request.Callback() { .... } );
        RequestAsyncTask status = request.executeAsync();

Same calls are called immediately after login and they work. I have a test app where it works. But in real app after few minutes after login it does not work.

like image 688
Max Avatar asked Mar 21 '13 19:03

Max


People also ask

What is an IllegalStateException in Java?

An IllegalStateException is a runtime exception in Java that is thrown to indicate that a method has been invoked at the wrong time. This exception is used to signal that a method is called at an illegal or inappropriate time. For example, once a thread has been started, it is not allowed to restart the same thread again.

Why we get IllegalStateException when we call start () method only once?

In the above example if we call start () method only once on thread t then we will not get any java.lang.IllegalStateException because we are not calling the start () method after the starting of thread (i.e we are not calling the start () method at an illegal or an inappropriate time.) Writing code in comment?

Is IllegalStateException checked or unchecked at runtime?

Whether the exception is checked or unchecked every exception occurs at run time only if there is no chance of occurring any exception at compile time. IllegalStateException is the child class of RuntimeException and hence it is an unchecked exception.


1 Answers

Are you running on UI thread? Wrap your code withrunOnUiThread

like this

Facebook SDK mentions that async calls must be done from UI thread

like image 164
Tema Avatar answered Nov 03 '22 01:11

Tema