Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 145
Registered: ‎05-01-2011
My Device: 9780
My Carrier: Developer

IOException in connection creation

Hi

 

I am facing IOException in connection creation.

 

Normal case :

 

If the user opens the app and for example after viewing the screens A->B->C and if the user clicks any item in the C screen, I called the httpconnectionfactory class and create a http connection and hit the particular url and get the values back and display in another screen called D. here no issues.

 

Problem is:

 

But if the user opens the app and for example after viewing the screens A->B->C and if the user press the red end button, After one or two days if the user again opens my app and he will get displayed the C screen and if the user clicks any item in that screen got IO Exception in the connection factory

 

Can any one tell me what should be the issue?

 

 

Trusted Contributor
Posts: 145
Registered: ‎05-01-2011
My Device: 9780
My Carrier: Developer

Re: IOException in connection creation

My HttpConnectionFactory class code is here:

 

public final class HttpConnectionFactory {

    private static HttpConnectionFactory instance = null;

    private HttpConnectionFactory() {
    }

    public static HttpConnectionFactory getInstance() {
        if(instance == null) {
            instance = new HttpConnectionFactory();
        }
        return instance;
    }

    public HttpConnection getConnection(final String url) {

        HttpConnection httpConnection = null;

        try {

            String url2 = url;
            final TransportDetective transDetective = new TransportDetective();

            if(transDetective.isCoverageAvailable(TransportDetective.TRANSPORT_MDS) || transDetective.isCoverageAvailable(TransportDetective.TRANSPORT_BIS_B)) {
                url2 = url + ";deviceside=false";
            }


            if(transDetective.isCoverageAvailable(TransportDetective.TRANSPORT_WAP2)) {
                url2 = url + ";deviceside=true" + ";ConnectionUID=" + transDetective.getSrWap2().getUid(); //WAP2 trans
            }


            if(transDetective.isCoverageAvailable(TransportDetective.TRANSPORT_TCP_WIFI)) {
                url2 = url + ";interface=wifi";
            }

            Logger.log("Http connection factory url --> " + url2);

 

            httpConnection = (HttpConnection) Connector.open(url2);
           
        } catch(final Exception e) {
            Logger.log(e);
        }
        return httpConnection;
    }

     public void closeConnection(HttpConnection httpConnection) {
        if(httpConnection != null){
            try {
                httpConnection.close();
            } catch(final Exception e) {
                Logger.log(e);
            }
        }
    }
}

 

 

Trusted Contributor
Posts: 145
Registered: ‎05-01-2011
My Device: 9780
My Carrier: Developer

Re: IOException in connection creation

[ Edited ]

Normally I called like

 

HttpConnection httpConnection = HttpConnectionFactory.getInstance().getConnection(Constants.NEWS);

 

if(httpConnection.getResponseCode() == HttpConnection.HTTP_OK) {

   

  InputStream stream = httpConnection.openInputStream();

 

  // Read the response data

 

  stream.close();
  HttpConnectionFactory.getInstance().closeConnection(httpConnection);

 

} else {

      // Print the response code
      HttpConnectionFactory.getInstance().closeConnection(httpConnection);
}

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: IOException in connection creation

Hi @

 

 

 

 

 

 

 
Trusted Contributor
Posts: 145
Registered: ‎05-01-2011
My Device: 9780
My Carrier: Developer

Re: IOException in connection creation

[ Edited ]

When the user left the app by pressing red end key button with the screen C then it should open C when clicked again and this is what I've got in my device

 

What else would you load? Please correct me if anything wrong

 

Normally if the user quits the app by pressing the back button then it will load from the beginning i.e., from A.

 

Yes from screen A & B the user definitely collected some values and I've today tested in my device that by opening the app and left the app by pressing the red end key and after 2.5hours again open the app and it loads the screen which I had when I left the app and I've got no issues and able to navigate to the previous screens also

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: IOException in connection creation

Using the red key is no different to pressing the menu and choosing switch application and selecting the Home Screen.  Your screen is still active, it is just not at the front.  So this processing should have no effect.  Neither should the delay. 

 

When you get an exception, can you log the Exception and the detail message? 

So instead of

Logger.log(e);

can you put

Logger.log(e.toString());

The toString will actually tell you what Exception you got too.

 

Until we know what sort of IOException you actually got, I don't think we can really help more. 

Trusted Contributor
Posts: 145
Registered: ‎05-01-2011
My Device: 9780
My Carrier: Developer

Re: IOException in connection creation

Thank you for your reply and friends said that the HttpConnectionFactory is a singleton class and might be that instance got invalid so after a long time if you open the app do refresh (re-initialize that instance), will that helpful?

 

and please can anyone review that HttpConnectionFactory class

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: IOException in connection creation

I've already reviewed your factory class, can't see anything in there that would cause a problem.

Trusted Contributor
Posts: 145
Registered: ‎05-01-2011
My Device: 9780
My Carrier: Developer

Re: IOException in connection creation

Thank you but I've faced a lot of connection related problems, all the other apps are workin in my device and browser also able to hit several pages but my app doesnot get able to hit the urls at sometimes

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: IOException in connection creation

Well let us look at the problems one at a time, starting with this one.  What is the actual exception you are getting?