Friday, September 09, 2005

BB : The dreaded "blocking operation not permitted on event dispatch thread"

Seen this message on your Blackberry?

“Uncaught Exception:blocking operation not permitted on event dispatch thread”

Have you done this?

A new class for threading:

class NewThread extends Thread

and in this you have a

public void run ()

Then in the main thread, you have

NewThread nt = new NewThread ();
nt.start ();

In NewThread, to access the UI you need:

UiApplication.getUiApplication().invokeLater
(new Runnable()
{public void run()
{
Dialog.alert ("Some message");
}
}
);

To access fields in the UI, use get / set methods (which are declared in the main thread) from the Runnable code above. I used to have the blocking exception until I changed to the above.

Enjoy!

No comments: