Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 685829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:57:44+00:00 2026-05-14T01:57:44+00:00

I am trying to get my Blackberry application to display a custom modal dialog,

  • 0

I am trying to get my Blackberry application to display a custom modal dialog, and have the opening thread wait until the user closes the dialog screen.

final Screen dialog = new FullScreen();

...// Fields are added to dialog

Application.getApplication().invokeAndWait(new Runnable()
{

    public void run()
    {
        Application.getUiApplication().pushModalScreen(dialog);             
    }
});

This is throwing an Exception which says “pushModalScreen called by a non-event thread” despite the fact that I am using invokeAndWait to call pushModalScreen from the event thread.

Any ideas about what the real problem is?

Here is the code to duplicate this problem:

package com.test;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class Application extends UiApplication {
    public static void main(String[] args)
    {
        new Application();
    }

    private Application()
    {
        new Thread()
        {
            public void run()
            {
                Application.this.enterEventDispatcher();
            }
        }.start();

        final Screen dialog = new FullScreen();
        final ButtonField closeButton = new ButtonField("Close Dialog");
        closeButton.setChangeListener(new FieldChangeListener()
        {

            public void fieldChanged(Field field, int context)
            {
                Application.getUiApplication().popScreen(dialog);
            }
        });
        dialog.add(closeButton); 
        Application.getApplication().invokeAndWait(new Runnable()
        {

            public void run()
            {
                try
                {
                    Application.getUiApplication().pushModalScreen(dialog);
                }
                catch (Exception e)
                {
                    // To see the Exception in the debugger
                    throw new RuntimeException(e.getMessage());
                }
            }
        });

        System.exit(0);
    }
}

I am using Component Package version 4.5.0.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:57:44+00:00Added an answer on May 14, 2026 at 1:57 am

    Building on Max Gontar’s observation that the Exception is not thrown when using invokeLater instead of invokeAndWait, the full solution is to implement invokeAndWait correctly out of invokeLater and Java’s synchronization methods:

    public static void invokeAndWait(final Application application,
        final Runnable runnable)
    {
        final Object syncEvent = new Object();
        synchronized(syncEvent)
        {
            application.invokeLater(new Runnable()
            {
    
                public void run()
                {   
                    runnable.run();
                    synchronized(syncEvent)
                    {
                        syncEvent.notify();
                    }
                }
            });
            try
            {
                syncEvent.wait();
            }
            catch (InterruptedException e)
            {
                // This should not happen
                throw new RuntimeException(e.getMessage());
            }
        }
    }
    

    Unfortunately, the invokeAndWait method cannot be overridden, so care must be used to call this static version instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get an example application running with blackberry-py. I adhered to
I am trying to develop a BlackBerry application. I have a BlackBerry 9700 with
Ive been trying to write my first Blackberry Adobe Flex application but get the
I am trying to run an Android application on a BlackBerry PlayBook Simulator using
I am trying to call HTTP request with network credential in blackberry. i have
I'm trying get bytes from bitmap in blackberry using the next method in Bitmap:
I have been trying to do some basic communications between a BlackBerry and a
I am new to Blackberry development and Im trying to simple get a BrowserField
I am trying to create an application on BlackBerry 9930 simulator that authenticate the
I am trying to get the Blackberry Messenger SDKs to work on my machine.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.