用黑莓下载图像并显示



我使用以下代码下载jpg图像并在blackberry curve 8900模拟器中显示。当我试图加载代码时,它会完全崩溃并停止响应。请有人帮我。

public DisplayBusinessDetail(String city,Business business)
{
    AbsoluteFieldManager absoluteFieldManager = new AbsoluteFieldManager();
    absoluteFieldManager.add(new BitmapField(connectServerForImage("http://www.mobileapples.com/Assets/Content/Wallpapers/Blackberry.jpg")),0,0);
    add(absoluteFieldManager);
}
public static Bitmap connectServerForImage(String url) {
      HttpConnection httpConnection = null;
      DataOutputStream httpDataOutput = null;
      InputStream httpInput = null;
      int rc;
      Bitmap bitmp = null;
      try {
       httpConnection = (HttpConnection) Connector.open(url);
       rc = httpConnection.getResponseCode();
       if (rc != HttpConnection.HTTP_OK) {
        throw new IOException("HTTP response code: " + rc);
       }
       httpInput = httpConnection.openInputStream();
       InputStream inp = httpInput;
       byte[] b = IOUtilities.streamToBytes(inp);
       EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length);
       return hai.getBitmap();
      } catch (Exception ex) {
       System.out.println("URL Bitmap Error........" + ex.getMessage());
      } finally {
       try {
        if (httpInput != null)
         httpInput.close();
        if (httpDataOutput != null)
         httpDataOutput.close();
        if (httpConnection != null)
         httpConnection.close();
       } catch (Exception e) {
        e.printStackTrace();
       }
      }
      return bitmp;
     }

提前感谢

您需要将套接字代码从主UI事件线程中移出。您的代码在UI线程上进行下载,这意味着在下载字节时没有UI响应。

相关内容

  • 没有找到相关文章

最新更新