2

I am working on a J2ME application, it makes a HTTP request and works accordingly to the response received.

Below is my code for HTTP request

public String sendHttpGet(String url, String str) throws Exception {
    HttpConnection hcon = null;
    DataInputStream dis = null;
    StringBuffer message = new StringBuffer();
    try {

        hcon = (HttpConnection) Connector.open(url);
        dis = new DataInputStream(hcon.openInputStream());
        int ch;
        while ((ch = dis.read()) != -1) {
            message.append((char)ch);
        }
    }catch(Exception e){   

    }finally {
        if (hcon != null) {
            hcon.close();
        }

        if (dis != null) {
            dis.close();
        }
        MyForm.show();
    }
    return message.toString();
}

It is working fine on non touch devices, but when I checked it on Nokia 500 touch phone,

the code executes till line

hcon = (HttpConnection) Connector.open(url);

without throwing any exception, it ends up to show first screen of the application (Main Menu).

Is there any limitation or problem?

Any solution?

gnat
  • 6,213
  • 108
  • 53
  • 73
  • 1
    As I can see in your code you're catching the Exception without logging or throwing a runtime exception. Try to log this exception and then print the stacktrace here that we can help yo – sandrozbinden Feb 02 '12 at 12:32
  • thanks for quick response, i have removed exception message(and logs) from the code above to remove extra code. i checked it by displaying message using Dialog. – Syed Muhammad Umair Feb 02 '12 at 12:58
  • I think your code is correct.Better you check your GPRS/network connection,settings in your mobile. – SIVAKUMAR.J Apr 14 '12 at 12:22

1 Answers1

1

Have you added permission in jad like this

MIDlet-Permissions: javax.microedition.io.Connector.http

or you can add this permission in netbean by following steps

  1. Right Click on project

  2. Click on Properties.

  3. Click on Application Descripter

  4. Select tab API Permission

  5. Click on Add Button And from list add javax.microedition.io.Connecter.http

Hope this will help you.

Mr. Sajid Shaikh
  • 7,051
  • 4
  • 21
  • 35