黑莓手机浏览问题
我开发了一个应用程序,通过使用诺基亚手机的 j2me 的移动应用程序访问网络,但是当我尝试在黑莓设备上运行此应用程序时,我遇到了问题,没有网站想要打开,它只是冻结 谁能帮助我,因为我找不到任何解决方案 这些是我在应用程序中使用的代码行,
我用这行代码从网络上读取内容
hc = (HttpConnection) Connector.open(url); dis = hc.openDataInputStream();
int dataleft = dis.available();
for (int j = 0; j < dataleft; j++) {
buffer.append((char) dis.read());
}
dis.close();
hc.close();
,并用这一行打开网站
this.platformRequest("http://stackoverflow.com/questions");
i developed an application that access the web through the mobile application using j2me for nokia cellphones but when i tried to run this application on blackberry devices i got a problem with it, no website want to be opened, it just freezes
so can anyone help me pls cos i could not find any solution for it
these r the lines of code that i'm using in the application
this line i'm using to read something from web
hc = (HttpConnection) Connector.open(url); dis = hc.openDataInputStream();
int dataleft = dis.available();
for (int j = 0; j < dataleft; j++) {
buffer.append((char) dis.read());
}
dis.close();
hc.close();
and this line to open a website
this.platformRequest("http://stackoverflow.com/questions");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在事件线程上运行该代码(其中存在一些问题...不要依赖 available() 来保证准确,您应该只调用 read() 直到它返回 -1),这是一个很大的问题- 黑莓手机上不行。该应用程序可能会尝试提示用户授予发出 HTTP 请求的权限,但由于偶数线程被阻止,因此无法执行此操作。这里有关于 BlackBerry 事件线程上该做什么和不该做什么的很好的描述:
http://www.blackberry.com/archives/182 Thinkingblackberry.com/archives/182
HttpConnection的API文档中也提到了:
API 文档位于:
http://www .blackberry.com/developers/docs/4.5.0api/javax/microedition/io/HttpConnection.html
You're probably running that code (which has some issues... don't depend on available() to be accurate, you should just call read() until it returns -1) on the event thread, which is a big no-no on the BlackBerry. The app is likely trying to prompt the user for permission to make the HTTP request, but since the even thread is blocked it can't do it. There's a pretty good description of what to do and not do on the BlackBerry event thread here:
http://www.thinkingblackberry.com/archives/182
It's also mentioned in the API documentation for HttpConnection:
The API docs are at:
http://www.blackberry.com/developers/docs/4.5.0api/javax/microedition/io/HttpConnection.html