开发者

BlackBerry IllegalStateException when clicking menu item

开发者 https://www.devze.com 2023-01-27 08:20 出处:网络
I want the following application flow to work: Start my application and show two buttons: Speaker and Mute

I want the following application flow to work:

  1. Start my application and show two buttons: Speaker and Mute
  2. After an incoming call is answered, the user goes to my application while the call is in progress.
  3. The user presses the Speaker button. It should invoke the "Activate Speakerphone" menu.

I can get the all menu items including "Activate Speakerphone". But while running menu it throws IllegalStateException.

my code is

public void fieldChanged(Field field, int context) {
    if(field==FldSpeaker){
            runMenuItem("Activate Speakerphone");
    }
}

private void runMenuItem(String menuItemText) {
        Screen screen = Ui.getUiEngine().getActiveScreen();
        Menu menu = screen.getMenu(0);
        for (int i = 0, cnt = menu.getSize(); i < cnt; i++)
                if(menu.getItem(i).toString().equalsIgnoreCase(menuItemText))
                        menu.getItem(i).run();//null error here
    }

I have tried

synchronized(Ui开发者_如何学编程Application.getApplication().getEventLock()){
    //Run code
}

..

synchronized(UiApplication.getApplication().getAppEventLock()){
    //Run Code
}

..

UiApplication.getUiApplication().invokeLater(new Runnable(){ 
    public void run(){
        //Run Code
    }
}

..

UiApplication.getUiApplication().invokeAndWait(new Runnable(){ 
    public void run(){
        //Run Code
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消