BlackBerry IllegalStateException when clicking menu item
I want the following application flow to work:
- Start my application and show two buttons: Speaker and Mute
- After an incoming call is answered, the user goes to my application while the call is in progress.
- 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
}
}
精彩评论