BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 07-15-2009, 01:55 AM   #1 (permalink)
New Member
Join Date: Jul 2009
Model: 7100T
Carrier: Programmer
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Angry HELP Needed IN HttpConnection Problem

Please Login to Remove!

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

import java.lang.String;
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 = "URL Goes Here;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);
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 =, bytesread, len - bytesread);
bytesread += actual;
} else {

int ch;

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

} catch (Exception e) {


Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

200 PCS Orthodontic Dental Mini Roth 022 3-4-5 Hooks Bracket Braces FLASH SALE
200 PCS Orthodontic Dental Mini Roth 022 3-4-5 Hooks Bracket Braces FLASH SALE pictureFlash-O-Lens Magnifier
Flash-O-Lens Magnifier picture5pcs ATF16V8B-15PU ATF16V8B High Performance Flash PLD DIP-20
5pcs ATF16V8B-15PU ATF16V8B High Performance Flash PLD DIP-20  picture10pcs ATF16V8B-15PU ATF16V8B High Performance Flash PLD DIP-20
10pcs ATF16V8B-15PU ATF16V8B High Performance Flash PLD DIP-20  pictureNew Lcd Usb Rt809f Universal Eprom Flash Vga Isp Avr Gal Pic Usb Programmer G
New Lcd Usb Rt809f Universal Eprom Flash Vga Isp Avr Gal Pic Usb Programmer G picture

Copyright 2004-2016
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.