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

Regular Contributor
Posts: 55
Registered: ‎09-01-2010
My Device: Not Specified
Accepted Solution

Blackberry HttpConnection prob to run in simulator

I want call a url and get the response data from the url from my Blackberry App. For that, I am using HttpConnection. Here is the code I am using:


import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Dialog;

import javax.microedition.io.Connector;
import javax.microedition.io.ContentConnection;
import javax.microedition.io.HttpConnection;
import java.io.DataInputStream;
import java.io.IOException;

public class TestApp extends UiApplication {

   private MainScreen _mainScreen;

   private static TestApp _app;

   public TestApp(){
       _mainScreen = new MainScreen();

       LabelField testField = new LabelField("hello world");



       HttpConnection c = null;
       DataInputStream dis = null;

       try {
        c = (HttpConnection)Connector.open("http://www.google.com");

        int rc = c.getResponseCode();
        if (rc != HttpConnection.HTTP_OK) {
            throw new IOException("HTTP response code: " + rc);
        dis = c.openDataInputStream();
        int len = (int)c.getLength();
        if (len > 0) {
            byte[] data = new byte[len];
        } else {
            int ch;
            while ((ch = dis.read()) != -1) {
       } catch(Exception e){
       }finally {

           try {
                if (dis != null)
                if (c != null)
            } catch (IOException e) {
            catch(NullPointerException e) {


    public static void main(String[] args) {
         _app = new TestApp();



When I try to run the code in simulator, I am getting '0', then '1' and after that after long time 'No stack trace' is appearing in debug window and as soon as the text is appearing, the level app with the text becomes visible in the simulator screen. There is no problem in the internet connection in simulator, I have set up the Wi-Fi and I have tested that I can open any website in the browser. What is problem in my code?

New Member
Posts: 1
Registered: ‎02-06-2012
My Device: curve9300
My Carrier: AIS

Re: Blackberry HttpConnection prob to run in simulator

you must start MDS 

MDS is service or bridge to connect internet for simulater 


install MDS and run it solve


download now

Regular Contributor
Posts: 60
Registered: ‎02-24-2011
My Device: Not Specified

Re: Blackberry HttpConnection prob to run in simulator

MDS is not a must... the problem is that in the connection string you're indeed specifying that it should use MDS.

use this:

c = (HttpConnection)Connector.open("http://www.google.com;deviceside=true;");