Note that there are some explanatory texts on larger screens.

plurals
  1. POBlackberry java, Open dialog from non UI thread using synchronized
    primarykey
    data
    text
    <p>I want to open a dialog from a separate thread, but when using the <code>synchronized</code> way, I get an error.</p> <p>If I use the method <code>invokeAndWait</code> everything works fine, however I don't understand why I can't use <code>synchronized</code>.</p> <p>Here is the code I call in my screen:</p> <pre><code>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(); } </code></pre> <p>Here is the HttpRequestDispatcherThread:</p> <pre><code>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 &lt; 0) contentLength = 10000; ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream responseData = connection.openInputStream(); byte[] buffer = new byte[contentLength]; int bytesRead = responseData.read(buffer); while (bytesRead &gt; 0) { baos.write(buffer, 0, bytesRead); bytesRead = responseData.read(buffer); } baos.close(); connection.close(); onComplete(); onSuccess(baos.toByteArray(), contentType); } catch (Exception e) { } } } </code></pre> <p>I get this error in the simulator: "JVM Error 104 Uncought: ArrayIndexOutOfBoundsException"</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload