Note that there are some explanatory texts on larger screens.

plurals
  1. POBlackberry WebBitmapField not showing image from url
    primarykey
    data
    text
    <p>I am using below code to display image from url comming from webservice. I am not getting any error but also not able to display the image.</p> <p>getWebData is a static method in my Utils class:</p> <pre><code>public static void getWebData(final String url, final WebDataCallback callback) throws IOException { Thread t = new Thread(new Runnable() { public void run() { HttpConnection connection = null; InputStream inputStream = null; try { connection = (HttpConnection) Connector.open(url, Connector.READ, true); inputStream = connection.openInputStream(); byte[] responseData = new byte[10000]; int length = 0; StringBuffer rawResponse = new StringBuffer(); while (-1 != (length = inputStream.read(responseData))) { rawResponse.append(new String(responseData, 0, length)); } int responseCode = connection.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException("HTTP response code: " + responseCode); } final String result = rawResponse.toString(); UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { callback.callback(result); } }); } catch (final Exception ex) { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { callback.callback("Exception (" + ex.getClass() + "): " + ex.getMessage()); } }); } finally { try { inputStream.close(); inputStream = null; connection.close(); connection = null; } catch(Exception e){} } } }); t.start(); } </code></pre> <p>The WebBitmapField that makes use of the getWebData method is below. All you need to do is pass a URL to the constructor and it'll load the image:</p> <pre><code>public class WebBitmapField extends BitmapField implements WebDataCallback { private EncodedImage bitmap = null; public WebBitmapField(String url) { try { Util.getWebData(url, this); } catch (Exception e) {} } public Bitmap getBitmap() { if (bitmap == null) return null; return bitmap.getBitmap(); } public void callback(final String data) { if (data.startsWith("Exception")) return; try { byte[] dataArray = data.getBytes(); bitmap = EncodedImage.createEncodedImage(dataArray, 0, dataArray.length); setImage(bitmap); } catch (final Exception e){} } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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