问题
I created a j2me program and ported it to the blackberry bold.
The program does some http queries. Every now and then these fail with the exception: 'tunnel failed'
My APN settings are correct (since sometimes it does work).
I connect with ';deviceside=true
' appended to the url
I notice that when the browser has just been active, the program always works. However when the browser hasn't been active for some minutes and I start the program, I get the tunnel failed errors.
回答1:
The problem with a few blackberry devices is that every other network connection fails. So you will have to try it once more when you receive an exception. So your connection code should be something like this
int numAttempts = 0;
boolean hasConnectedSuccessfully = false;
while(numAttempts < 2 && !hasConnectedSuccessfully)
{
try
{
// do the http connection
hasConnectedSuccessfully = true;
}
catch(Exception e)
{
hasConnectedSuccessfully = false;
}
finally
{
//close the connections
}
numAttempts++;
}
Hope this should fix your problem
回答2:
As a test, you might want to try adding the APN settings on the URL itself to see if that helps. I assume you have good signal strength?
回答3:
As silly as this sounds even if you are only reading from the connection, make sure when opening the connector you open it as read/write
String url = "http://www.google.com";
HttpConnection connection = (HttpConnection)Connector.open(url, Connector.READ_WRITE, true);
来源:https://stackoverflow.com/questions/1126018/tunnel-failed-in-blackberry-bold-why