单击菜单项时出现 BlackBerry IllegalStateException

发布于 2024-10-05 12:40:20 字数 1275 浏览 0 评论 0原文

我希望以下应用程序流程正常工作:

  1. 启动我的应用程序并显示两个按钮:扬声器和静音
  2. 接听来电后,用户在通话过程中转到我的应用程序。
  3. 用户按下扬声器按钮。它应该调用“激活扬声器”菜单。

我可以获得所有菜单项,包括“激活免提电话”。但是在运行菜单时它会抛出 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:

  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(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文