Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 3
Registered: ‎07-15-2009
My Device: Not Specified
Accepted Solution

HELP Needed IN HttpConnection Problem

Hi I'm a Newbie to Blackberry Development..I'm try to read the Data from the URL through HttpConnection. The below is my code. When i invoke through simulator the code, The following code does not executes.. System.out.println("MDS getResponseCode"+c.getResponseCode()); There is no exception too.. Pls help Whats wrong in my code..

Thanks in Advance -Poy

import java.io.IOException;
import java.io.InputStream;
import java.lang.String;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

// Main class
public class HttpCxn extends UiApplication {

// Starting point
public static void main(String[] args) {
HttpCxn httpCxn = new HttpCxn();

// Calls initial screen
public HttpCxn() {
pushScreen(new HttpCxnScreen());


class HttpCxnScreen extends MainScreen {

// Declare my initial variables

ButtonField submitButton = new ButtonField("Submit", ButtonField.CONSUME_CLICK);
HttpCxnScreen screen = this;

// Main screen, including entries for Character/Server names
public HttpCxnScreen() {

// Create Label for title for main screen
LabelField mainTitle = new LabelField("HTTP CONNECTION", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
// Set title to above label
// Add other items to screen


// Create functionality of submit button
submitButton.setChangeListener(new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
Thread postnameThread = new Thread(new ServerConnection());



// http connection class
class ServerConnection extends Thread {

String url = ";deviceside=false";

// Method called by submit button
public ServerConnection() {

public void run() {
HttpConnection c = null;
InputStream is = null;
String response;
int rc;

try {
StringBuffer buffer = new StringBuffer();
c = (HttpConnection)Connector.open(url);
System.out.println("AZtest"+c);//my debugger does not passed this line
// Getting the response code will open the connection,
// send the request, and read the HTTP response headers.
// The headers are stored until requested.
System.out.println("MDS getResponseCode"+c.getResponseCode());
rc = c.getResponseCode();
System.out.println("MDS CHECK"+rc);
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);

is = c.openInputStream();

// Get the ContentType
String type = c.getType();

// Get the length and process the data
int len = (int)c.getLength();
if (len > 0) {
int actual = 0;
int bytesread = 0 ;
byte[] data = new byte[len];
while ((bytesread != len) && (actual != -1)) {
actual = is.read(data, bytesread, len - bytesread);
bytesread += actual;
} else {

int ch;

while ((ch = is.read()) != -1) {
ch = is.read();
buffer.append((char) ch);
response = buffer.toString();

} catch (Exception e) {



BlackBerry Development Advisor
Posts: 15,884
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: HELP Needed IN HttpConnection Problem

Do you mean that particular line of code is skipped or is the application blocking on that line?  What BlackBerry Smartphone model and BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: HELP Needed IN HttpConnection Problem

This post might help.

Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Developer
Posts: 3
Registered: ‎07-15-2009
My Device: Not Specified

Re: HELP Needed IN HttpConnection Problem

Hi MSohm and Ted_Hopp, 

Thank for both you for spending the valuable time.

The problem is with enabling  MDS services.

I was using BlackBerry JDE Plug-in for Eclipse,with enabled MDS Services .But it was not working properly.Then I have deployed my sample in BlackBerry JDE and invoked MDS services.It works fine Now.