Welcome!

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

Reply
Developer
nankerphelgue
Posts: 27
Registered: ‎12-23-2008
My Device: 10000
My Carrier: Developer

Error :UI engine accessed without holding the event lock.

Mmm im a very newbie developing for blackberry and i get this error
can you help me? this is my idea :
----------------------------------------------------------------------------------------------
Main Class
public static void main(String[] args)
{
Main main = new Main();
main.execute();
main.enterEventDispatcher();
}

private void execute(){
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
pushScreen(new InboxScreen());
}
});
}
-------------------------------------------------------------------------------------------------------------------
Inbox Screen Class
public InboxScreen(){
...
...
Thread threadGetInboxData = new Thread(){
public void run(){
InboxController.getResults(1, "XXXXXX");
}
};
....
...
}
public static void updateResultInboxContainer(TableListField tlf){
synchronized (UiApplication.getApplication().getEventLock()) {
// vfm is a manager o container for the tlf
vfm.add(tlf);
}
}
-------------------------------------------------------------------------------------------------------------------
InboxController
public static void getResults(String _pin){
...
...
...
ConnectionRecieve serverConnection = new ConnectionRecieve(URL, HOST, queryString, data, false);
Thread thread = new Thread(serverConnection);
thread.start();
while(true){
inputStreamResponse = serverConnection.getResponse();
if(serverConnection.getErrorConnection() || inputStreamResponse!=null) {
break;
}

...
...
...
screenReference.updateResultInboxContainer(tableresults);

}

----------------- -------------------------------------------------------------------------------------

ConnectionRecieve extends Thread{
    ...
    ...   
   
    public ConnectionRecieve(String url, String host, String queryString, byte[] data,boolean mdsSetting){

....

....


    }

    public void run(){
       
        try{
            url += queryString;
            url += Util.appendConnectionString(mdsSetting);
           
            System.out.println("URL :"+url);
           
            int dataLength = data.length;

            if (url.indexOf("NOIPPP") > -1) {
                errorConnection = true;
            }
            else {
                // Create connection
                httpConnection = (HttpConnection) Connector.open(url);
                httpConnection.setRequestMethod(HttpConnection.POST);
                httpConnection.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
                httpConnection.setRequestProperty("Host", host);
                httpConnection.setRequestProperty("Content-Length", Integer.toString(dataLength));
                httpConnection.setRequestProperty("Expect", "100-continue");
                // Output stream
                System.out.println("Output stream");
                outputStream = httpConnection.openDataOutputStream();
                outputStream.write(data, 0, dataLength);
                // Input stream
                System.out.println("Input stream");
                inputStream = httpConnection.openInputStream();
            }
        }
        catch(IOException e){
            System.out.println("Error Connection, try it again");
            errorConnection = true;
        }
    }

    public InputStream getResponse(){
        return inputStream;
    }
   
    public boolean getErrorConnection(){
        return errorConnection;
    }
   
}

Please use plain text.
Administrator
MSohm
Posts: 14,241
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Error :UI engine accessed without holding the event lock.

Please see the link below for an explanation of this exception and sample code that prevents it.

 

How To - Manage UI interactions
Article Number: DB-00134

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Contributor
marcwickens
Posts: 8
Registered: ‎03-28-2011
My Device: N/A
My Carrier: N/A

Re: Error :UI engine accessed without holding the event lock.

I also had this problem when I was trying to show a PopUp screen before I had any other screens on the stack. Putting my main screen into the stack, and then loading the Popup screen solved this.

Please use plain text.
Developer
rihan007
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Error :UI engine accessed without holding the event lock.

[ Edited ]

try this

 

public static void main(String[] args)
{

Main main = new Main();
 
main.enterEventDispatcher();
main.execute();
}
Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Error :UI engine accessed without holding the event lock.

rihan007, your code is bogus. enterEventDispatchter does not return, therefore execute will never be called.
see
http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/system/Application.html#enterE...
----------------------------------------------------------
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
Please use plain text.
Developer
rihan007
Posts: 455
Registered: ‎01-14-2009
My Device: Apple iPhone 3GS 16GB

Re: Error :UI engine accessed without holding the event lock.

oops. my bad. thanks for pointing it out.!!!
Please use plain text.
Contributor
liuksmith
Posts: 41
Registered: ‎09-13-2011
My Device: BlackBerry Z10 Limited Edition
My Carrier: TIM - Italy

Re: Error :UI engine accessed without holding the event lock.

Hi Mark

I 've read the how-to but I don't know where I can interact in my app.

I've developed an application that is a contenthandler for a custom file type, when I exchange this file through BBM and click button "view" after that download is complete I pick this exception : java.lang.illegalStateException: UI engine access without holding the event lock.

On handheld this exception is not shown but I find it in systemlog (alt+lglg) and my app does not work well.

 

thank you in advance

Luca

 

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Error :UI engine accessed without holding the event lock.

liuksmith, please open an own thread for your question.
you can use invokelater when you http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/system/Application.html#invoke... the UI from a separate thread to solve your problem
----------------------------------------------------------
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
Please use plain text.