1

I've created a simple app that calls a url inside a browserfield whenever a phonecall is initiated or received, but I keep on getting the exception:

UI engine accessed without holding the event lock.

I read somewhere that I have to make use of Global Events, but I don't know how to do that. I have been struggling a long time on this and would appreciate any help on getting the urls to load when a call is iniated or dialled without getting an error.

My code:

public class BackgroundApp extends MainScreen implements PhoneListener {

    BrowserField bf = new BrowserField();

    public BackgroundApp(){
        super();
        Phone.addPhoneListener(this); //Phonelistener added to code
        add(bf);
    }

    public void callIncoming(int callId) { //Method to listen for an incoming call and get the number
        try {
            bf.requestContent("http://www.yahoo.com/");
        } catch (Exception me) {
            me.printStackTrace();
        }
    }

    public void callAdded(int arg0) {}
    public void callAnswered(int callId) {}
    public void callConferenceCallEstablished(int callId) {}
    public void callConnected(int callId) {}
    public void callDirectConnectConnected(int callId) {}
    public void callDirectConnectDisconnected(int callId) {}
    public void callDisconnected(int callId) {}
    public void callEndedByUser(int callId) {}
    public void callFailed(int callId, int reason) {}
    public void callHeld(int callId) {}

    public void callInitiated(int callid) {
        try {
            bf.requestContent("http://www.google.com/");
        } catch (Exception me) {
            me.printStackTrace();
        }
    }

    public void callRemoved(int callId) {}
    public void callResumed(int callId) {}  /
    public void callWaiting(int callid) {}
    public void conferenceCallDisconnected(int callId) {}

    public boolean onClose() {
        System.exit(0);
        return true;
    }
}
Nate
  • 31,017
  • 13
  • 83
  • 207

1 Answers1

0

Replace this

bf.requestContent("something");

with

 synchronized (UiApplication.getEventLock()) 
 {
    bf.requestContent("http://www.yahoo.com/");
 }

or use like this:

synchronized (UiApplication.getEventLock()) 
{
    UiApplication.getUiApplication().invokeLater(new Runnable() 
    {
        public void run() 
        {
            bf.requestContent("http://www.yahoo.com/");
        }
    });
}
alishaik786
  • 3,696
  • 2
  • 17
  • 25