Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Contributor
Posts: 8
Registered: ‎07-25-2013
My Device: none
My Carrier: none
Accepted Solution

Event Lock Hold Error

First of all to get the small details out of the way:


I am using a blackberry bold device

I am using eclipse SDK and the BB 5.0 SDK


Error being thrown:

java.lang.IllegalStateException: UI engine accessed without holding the event lock


The code throwing it: 

public PlaylistScreen(String djName, String country)





  add(list = new VerticalFieldManager());

  API.Playlists.getPlaylistSongs(djName, country, this);  <---- This line is throwing the error



that line is running this method:

public void httpCallback(HttpResponse r) 


  if ( r.getResponseCode() == HTTP_OK){

    JSONArray a;



      a = new JSONArray(r.getResponseBody().toString());

      for(int i = 0; i < a.length(); i++)


        list.add(new PlaylistSongField(this, new JSONPlaylistSong(a.getJSONObject(i).toString())));  <- This line is throwing the error


    } catch (JSONException e1) {} catch (org.json.me.JSONException e) {}




That line calls the constructor for a field that I am adding into the list.

This is all run under this line:

MainApplication.getInstance().invokeAndWaitPushScreenNew(new PlaylistScreen("1111", "us"));


which is running:


public void invokeAndWaitPushScreenNew(final Screen s)


  invokeAndWait(new Runnable()


    public void run()







I have tried this with both invokeLater and invokeAndWait and both throw this exception.

I have looked at This Post and other articles on the support forum but haven't been able to find an answer or way around.  I have not tried to use the syncronized methods as I haven't worked with them before.  I will be trying this out soon.

I have also tried to access the link that peter_strange has linked at the bottom of the post and it doesn't work.  I have tried other ways to find the article and cannot find it.  I am at a loss of how to get around the event lock.

Posts: 16,893
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Event Lock Hold Error

the httpCallback indicates that the networking is done on a separate theead (as it should be).
that means you have to use invokelater to run things on the UI thread.
wrap the offending line into an invokelater block.

for further information see
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter