InputStream return null in device blackberry

2019-05-20 12:48发布

I am getting the inputstream using the connection class in blackberry like this

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

it works well in simulator, but the input stream returns null when run at device. Can please tell the solution for this problem. Thanks in advance.

标签: blackberry
3条回答
不美不萌又怎样
2楼-- · 2019-05-20 13:29
做自己的国王
3楼-- · 2019-05-20 13:38

First, HttpConnection is an interface, not a class, so I don't see how your code could even compile. Then, you don't have any connection parameters on your url, so you are at the mercy of whatever network the device is on. You also need to check the return code after making a connection to check that it succeeded. Only then can you try to open an input stream.

You might want to take a look at the sample networking code by Peter Strange.

查看更多
乱世女痞
4楼-- · 2019-05-20 13:51

On real device you need to append appropriate URL parameter according to connection type(WiFi/BES/BIS/WAP2/TCP) you are using.

    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");
查看更多
登录 后发表回答