【发布时间】:2012-02-15 03:49:40
【问题描述】:
每个人。我是新来的,这是我的第一篇文章。 我正在创建一个简单的应用程序来获取网络内容。下面是我的代码。问题是,我无法在模拟器上运行它。没有错误,没有对话框,只是完全无法打开。如果有人可以帮助我......
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class HTTPClient extends UiApplication {
LabelField test;
MainScreen screen = new MainScreen();
public static void main(String[] args)
{
HTTPClient theApp = new HTTPClient();
theApp.enterEventDispatcher();
}
public HTTPClient()
{
getPage("http://google.com");
}
public void getPage(String url) {
String response = "";
try {
StreamConnection s = (StreamConnection)Connector.open(url);
InputStream input = s.openInputStream();
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
while( -1 != (len = input.read(data))) {
raw.append(new String(data, 0, len));
}
response = raw.toString();
show(response);
input.close();
s.close();
} catch(Exception e) { }
}
public void show(String response) {
test = new LabelField(response);
screen.add(test);
pushScreen(screen);
}
}
【问题讨论】:
-
在 BB 模拟器上运行应用程序时,在 Eclipse 的“控制台”视图中显示的输出中查找
Exception。 -
您也可以在BB模拟器的“事件日志”(BB模拟器->工具->显示事件日志)中查找
Exception。 -
@error.exit 这是异常 java.io.InterruptedIOException: Local connection timed out after ~ 12000
-
可能会抛出
Exception,因为 BlackBerry MDS Connection Service 未启用(在运行/调试配置中)。请查看下面的答案以获取更多详细信息。
标签: java multithreading blackberry httpconnection