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 9207403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:22:46+00:00 2026-06-18T00:22:46+00:00

I want to open a dialog from a separate thread, but when using the

  • 0

I want to open a dialog from a separate thread, but when using the synchronized way, I get an error.

If I use the method invokeAndWait everything works fine, however I don’t understand why I can’t use synchronized.

Here is the code I call in my screen:

public void Login() {

        new HttpRequestDispatcher("http://www.google.com", "GET", this) {
            public void onSuccess(byte[] baos, String contentType) {
                synchronized(UiApplication.getEventLock()){
                    Dialog.alert("Cooooooool....");
                }
            }
            public void onFail(String message){
                synchronized(UiApplication.getEventLock()){
                    Dialog.alert(message);
                }
            }
        }.start();
    }

Here is the HttpRequestDispatcherThread:

public abstract class HttpRequestDispatcher extends Thread {

    String url;
    String method;
    Screen scr;

    public HttpRequestDispatcher(String url, String method, Screen scr) {
        this.url = url;
        this.method = method;
        this.scr = scr;
    }

    public abstract void onFail(String message);
    public abstract void onSuccess(byte[] baos, String contentType);
    public void beforeSend() {}
    public void onComplete() {}

    public void run() {

        beforeSend();

        try {

            HttpConnection connection = (HttpConnection) Connector.open(url);
            connection.setRequestMethod(method);

            int responseCode = connection.getResponseCode();
            if (responseCode != HttpConnection.HTTP_OK) {
                onFail(connection.getResponseMessage());
                connection.close();
                return;
            }

            String contentType = connection.getHeaderField("Content-type");
            int contentLength = (int) connection.getLength();
            if (contentLength < 0)
                contentLength = 10000;

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            InputStream responseData = connection.openInputStream();
            byte[] buffer = new byte[contentLength];
            int bytesRead = responseData.read(buffer);

            while (bytesRead > 0) {
                baos.write(buffer, 0, bytesRead);
                bytesRead = responseData.read(buffer);
            }

            baos.close();
            connection.close();

            onComplete();
            onSuccess(baos.toByteArray(), contentType);

        } catch (Exception e) {
        }
    }
}

I get this error in the simulator: “JVM Error 104 Uncought: ArrayIndexOutOfBoundsException”

  • 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-06-18T00:22:47+00:00Added an answer on June 18, 2026 at 12:22 am

    Found the answer:

    “Dialogs cannot be opened from a thread other than the main event thread”

    Synchronized executes a statement in the current thread but holding the event lock, instead, invokeAndWait, sends the statement to an event queue to be executed later on the main event thread.

    Thats why my code didn’t work with synchronized

    This helped: https://stackoverflow.com/a/6515542/1680787

    @Nate, you are absolutly right about my catch blocks, +1 and my bad, just new to blackberry.

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

Sidebar

Related Questions

I want to open a file dialog via FileReference.browse() but I get #2176 error
I want to use the sharer.php popup to open the share dialog, but would
I'm using jquery for modal dialogs. I want to open model dialog from one
I want to open a MFC modeless dialog from a MFC dll injected into
I want to open a custom dialog in onHandleIntent() method of an IntentService class,
I want to resize the dialog dynamically just before I open it, but this
Several forms from my application use the same open file dialog. I need to
I want to know how can we open a file dialog from withing a
I want to show a dialog which gets its content from server dynamically using
There is any way (from browser) to read local file without open dialog? Can

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.