PDA

View Full Version : Please Help in HttpConnection?


ahmadgee
04-28-2008, 05:52 AM
Hi every body,

I am new in BB programming and try to connect to internet through the http connection. When I ran this programme and clicked on the project icon using simulator Then it could not open the icon and could not display error as well.

Can any body help me where am I wrong.
Thanks and kind regards,

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.io.*;

class ReadWebpageContents extends UiApplication{
HttpConnection connection = null;
InputStream stream = null;
StringBuffer b = new StringBuffer();

public void getReadWebpageContents(){

try {
connection = (HttpConnection)Connector.open
("http://www.cinq.net/bbtest.txt");
stream = connection.openInputStream();
int ch;
while ((ch = stream.read()) != -1) {
b.append((char) ch);
}
MainScreen screen=new MainScreen();
screen.add(new LabelField(b.toString()));
pushScreen(screen);

System.out.println("connection closed");
}catch (IOException e) {

}
}

public static void main(String args[]){
ReadWebpageContents rwc=new ReadWebpageContents();
rwc.getReadWebpageContents();
rwc.enterEventDispatcher();
}
}

Dinan3
04-28-2008, 07:12 AM
ahmadee, welcome to the forums.

you might get better help if you post this in our developer's forum.

Good Luck!

ahmadgee
04-28-2008, 08:02 AM
Thank you very much for the direction.
Best regards,