BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-04-2008, 02:04 PM   #1 (permalink)
New Member
 
Join Date: Mar 2008
Model: 8820
PIN: N/A
Carrier: Airtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default HttpConnection problem using midlet

Please Login to Remove!

Hi,
I am using standard midlet code which i run on Motorola and Nokia devices. The application is working fine on actual device but i can not connect to the server using HttpConnection GCF.

Here is the sample of code which is running perfectly on emulator but displaying error on device and i am unable to eastablish the connection.

Please guide me.

Thanks
Shailesh

---------------
Code:


import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class TestMidlet extends MIDlet implements Runnable,CommandListener
{
private Thread thread;
Display display;
Form frm=new Form("Response");
Command cmd=new Command("Exit",Command.OK,0);
public void startApp ()
{
display=Display.getDisplay(this);
frm.addCommand(cmd);
frm.setCommandListener(this);
display.setCurrent(frm);
try
{
thread = new Thread (this);
thread.start ();
}
catch(Exception e)
{
System.out.println(">>> Exception Caught : " + e.toString ());
}
finally
{
System.out.println("-- startApp() : end -- ");
}
}


public void commandAction(Command c,Displayable d)
{
if(c==cmd){
this.notifyDestroyed();
}
}
public void pauseApp ()
{
}

public void destroyApp (boolean unconditional)
{
}
StringBuffer str=new StringBuffer();
public void run ()
{
try
{
HttpConnection con = (HttpConnection) Connector.open("http://www.google.com");
frm.append("Tryig to Connect..");
InputStream is = con.openInputStream();
frm.append("\n\nNow Connecting..");
int c = 0;
while ((c = is.read()) != -1)
{
str.append((char) c);
}
frm.append("\n\n Connected: "+str);
display.setCurrent(frm);
is.close();
con.close();
}
catch(Exception e)
{
frm.append("\n\nException :" + e.toString());
}
finally
{
System.out.println("-- run() : end -- ");
}
}

}
Offline  
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





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.