【问题标题】:Any simulator needed for Blackberry http connection?黑莓http连接需要任何模拟器吗?
【发布时间】:2011-12-08 13:07:39
【问题描述】:

我正在尝试从我的黑莓模拟器测试 http 连接,但没有任何反应。我需要一个 MDS 模拟器来运行这个应用程序吗? 我正在使用 Eclipse Helios BlackBerry Java 插件 1.5.0。我还在我的系统中安装了黑莓 JDE。

void getViaHttpConnection(String url) throws IOException {
        HttpConnection c = null;
        InputStream is = null;
        int rc;

        try {
            c = (HttpConnection)Connector.open(url);
            RichTextField rt = new RichTextField("TEST LENGTH");
            // Getting the response code will open the connection,
            // send the request, and read the HTTP response headers.
            // The headers are stored until requested.
            rc = c.getResponseCode();
            if (rc != HttpConnection.HTTP_OK) {
                throw new IOException("HTTP response code: " + rc);
            }

            is = c.openInputStream();

            // Get the ContentType
            String type = c.getType();

            // Get the length and process the data
            int len = (int)c.getLength();
            if (len > 0) {
                rt = new RichTextField("TEST LENGTH"+len);
                int actual = 0;
                int bytesread = 0 ;
                byte[] data = new byte[len];
                while ((bytesread != len) && (actual != -1)) {
                   actual = is.read(data, bytesread, len - bytesread);
                   bytesread += actual;
                }
            } else {
                rt = new RichTextField("GREATER LENGTH"+len);
                int ch;
                while ((ch = is.read()) != -1) {

                }
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Not an HTTP URL");
        } finally {
            if (is != null)
                is.close();
            if (c != null)
                c.close();
        }
    }

非常感谢您的帮助, 谢谢, VKS

【问题讨论】:

  • 出于好奇,您如何实际检测这是否成功?从外观上看,没有任何东西可以表明您实际上得到了字符串。如果它没有抛出任何异常,那么它很可能正在工作。
  • 但我在 3 个条件下添加了 3 个 RichTextField,在屏幕中找不到?
  • 您正在创建新的RichTextFields,但实际上并未将它们添加到屏幕上。

标签: java blackberry blackberry-jde


【解决方案1】:

您需要运行 MDS-CS 模拟器才能使用黑莓模拟器连接到互联网

【讨论】:

    【解决方案2】:

    不,您不需要使用 MDS-CS。

    您可以通过转到管理连接->设置 Wi-Fi 网络并连接到“默认 WLAN 网络”来配置模拟器以使用您 PC 的正常网络连接(绕过 MDS-CS)。

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多