Troubleshooting guide

122
BlackBerry Java Development Environment Development Guide
int i = 0;
for (i = HTTP_PROTOCOL.length - 1; i >= 0; --i) {
if ( -1 != lcase.indexOf(HTTP_PROTOCOL[i]) ) {
validHeader = true;
break;
}
}
if ( !validHeader ) {
// Prepend the protocol specifier if it is missing.
url = HTTP_PROTOCOL[0] + url;
}
// Create a new thread for connection operations.
_connectionThread.fetch(url);
}
// Display the content.
private void updateContent(final String text) {
/* This technique creates several short-lived objects but avoids
* the threading issues involved in creating a static Runnable and
* setting the text.
*/
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
_content.setText(text);
}
});
}
}
Use HTTP authentication
Task Steps
Before opening an HTTP connection,
verify that the BlackBerry® device is in a
wireless coverage area.
>Use the CoverageInfo class and CoverageStatusListener interface of the
net.rim.device.api.system package to make sure that the BlackBerry device is in a
wireless coverage area.
Open an HTTP connection. 1. Invoke Connector.open(), using the HTTP location of the protected resource.
2. Cast and store the returned object as a StreamConnection.
StreamConnection s = (StreamConnection)Connector.open("http://
mysite.com/myProtectedFile.txt");
3. Cast and store the StreamConnection object as an HTTPConnection object.
HttpConnection httpConn = (HttpConnection)s;
Determine the status of the HTTP
connection.
>Invoke HttpConnection.getResponseCode().
int status = httpConn.getResponseCode();