设备blackberry中的InputStream返回null

设备blackberry中的InputStream返回null,blackberry,Blackberry,我使用blackberry中的connection类获取inputstream,如下所示 HttpConnection httpConnection = new HttpConnection("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml"); InputStream is = httpConnection.StreamConnection(); 它在模拟器中运行良好,但在设备上运行时,输入流返回null。请告诉我这个问题的解决办

我使用blackberry中的connection类获取inputstream,如下所示

HttpConnection httpConnection = new HttpConnection("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml");
InputStream is = httpConnection.StreamConnection();

它在模拟器中运行良好,但在设备上运行时,输入流返回null。请告诉我这个问题的解决办法。提前感谢。

首先,HttpConnection是一个接口,而不是一个类,所以我不知道您的代码是如何编译的。然后,您的url上没有任何连接参数,因此您可以任由设备所在的网络支配。您还需要在建立连接后检查返回代码,以检查连接是否成功。只有这样,您才能尝试打开输入流


您可能需要查看。

您需要查看以下线程:


在真实设备上,您需要根据您使用的连接类型(WiFi/BES/BIS/WAP2/TCP)附加适当的URL参数

    For example if you are using BES connection:

    streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml;deviceside=false");

and if your are using WiFi:

    streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml;deviceside=true;interface=wifi");

and For WAP2/TCP:

        streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml;deviceside=true");

谢谢这里的代码StreamConnection streamConn;DataInputStream\u inputStream;尝试{synchronized(UiApplication.getEventLock()){streamConn=(StreamConnection)Connector.open(“);_inputStream=new DataInputStream(streamConn.openInputStream());}请不要将代码放在注释中-它不会格式化-改为编辑原始问题。