我希望以下应用程序流程能够正常运行:
我可以获得所有菜单项,包括“激活免提电话”。但是在运行菜单时会抛出IllegalStateException。
我的代码是
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
}
我试过了
synchronized(UiApplication.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
}
}