Java 黑莓http连接需要什么模拟器?
我试图从我的黑莓模拟器测试http连接,但什么也没发生。运行此应用程序是否需要MDS模拟器? 我正在使用Eclipse Helios BlackBerry Java插件1.5.0。我还在我的系统中安装了blackberry JDEJava 黑莓http连接需要什么模拟器?,java,blackberry,blackberry-jde,Java,Blackberry,Blackberry Jde,我试图从我的黑莓模拟器测试http连接,但什么也没发生。运行此应用程序是否需要MDS模拟器? 我正在使用Eclipse Helios BlackBerry Java插件1.5.0。我还在我的系统中安装了blackberry JDE void getViaHttpConnection(String url) throws IOException { HttpConnection c = null; InputStream is = null; int
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您需要运行MDS-CS模拟器,才能使用黑莓模拟器连接到互联网不,您不需要使用MDS-CS
通过进入“管理连接->设置Wi-Fi网络并连接到“默认WLAN网络”,您可以将模拟器配置为使用电脑的正常网络连接(绕过MDS-CS)。出于好奇,您实际上是如何检测这是否成功的?从它来看,实际上没有任何东西表明你真的得到了字符串。如果它没有抛出任何异常,它可能会很好地工作。但我在3种情况下添加了3个RichTextFields,它在屏幕中找不到?您正在创建新的
RichTextField
s,但实际上并没有将它们添加到屏幕中。