单击菜单项时出现 BlackBerry IllegalStateException
我希望以下应用程序流程正常工作:
- 启动我的应用程序并显示两个按钮:扬声器和静音
- 接听来电后,用户在通话过程中转到我的应用程序。
- 用户按下扬声器按钮。它应该调用“激活扬声器”菜单。
我可以获得所有菜单项,包括“激活免提电话”。但是在运行菜单时它会抛出 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
}
}
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(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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论