Hello all,

I am having a problem using HttpConnection.close() in my MIDlet. This happens on certain devices only like N5310, it is working fine on other devices.


here is my code:

try{
     HttpConnection http = (HttpConnection) Connector.open(URL);
     http.setRequestMethod(HttpConnection.GET);
     ....//some other processes here.
}catch (Exception e){
}finally{
      if(http != null)
            http.close()
}

When I try to run this, the letter [G] symbol that denotes an open connection on my device is not disappearing (in 5310 ONLY).

Anybody here knows how to close the GPRS or any connections in j2me aside from this close() method?

Thank you!

You declared HttpConnection inside "try" block and there for made it local variable of this block and not accessible in "finally" block. Make declaration outside and you are fine

HttpConnection http
try{
    http = (HttpConnection) Connector.open(URL);

PS: Please use code tags [code=Java]YOUR CODE [/code] or [codeYOUR CODE [/code] for next time

Thank you for the reply, I did it but it doesn't help. Are there any other ways to close all the connections in the device. Maybe close() method could not be recognized by this 5310 so the connections will remain open.

It is the correct way to shut down connection with close() and it does work on all devices. It is more likely that phone itself does not update GUI to hide this icon, nothing unusual.

I asked that because whenever I connect to a certain URL for the second time, I can't get its response ([G] is still there because I connected to http previously) and causes the phone to send http request once again (retry?). And when the retry request has been fetched, I can now get its response (second one which is not supposed to be). I need to have only one request. Maybe this has something to do with cache, cookies or something? Any idea about this?

When I test my MIDlet on other devices, the [G] symbol is disappearing and sending requests is sent only once which is normal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.