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
Contributor
Posts: 15
Registered: ‎09-02-2010
My Device: Not Specified

Connector - problem with WiFi

Hi,

 

I have a problem with WiFi when I create an HttpConnection.

I have this line code:

 

httpConnection = (HttpConnection)Connector.open(url + connectionType, Connector.READ_WRITE, true);

where connectionType is ";interface=wifi" if WiFi is actived.

 

For BIS/BES connection type it's OK, also for WiFi it's OK, but when WiFi changes (or I go out WiFi signal and I return into it) I revice this error:

 

java.io.IOException.

 

Why?

Developer
Posts: 107
Registered: ‎05-26-2011
My Device: Torch
My Carrier: Mobilink

Re: Connector - problem with WiFi

Without lookng at the code i cant say much but

 

 u r saying that your code works fine when wifi is active.

 

if you go out and make  http request it will always throw the exception if it didnot get sufficient coverage for wifi ...

 

 

 

Contributor
Posts: 15
Registered: ‎09-02-2010
My Device: Not Specified

Re: Connector - problem with WiFi

This is my function to determinate the connection type:

    public static String getConnectionType() {
        
        final String CON_BIS = ";deviceside=false;ConnectionType=mdspublic";
        final String CON_BES = ";deviceside=false";
        final String CON_TCPIP = ";deviceside=true";
//        final String CON_WIFI = ";deviceside=true;interface=wifi";
        final String CON_WIFI = ";interface=wifi";
        
        // Emulatore
        if(DeviceInfo.isSimulator()) {
            return "";
        }
        
        // Wifi
        if(WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
            return CON_WIFI;
        }

        // Ricava la stringa di connessione
        boolean _bisSupport=false;
        boolean _mdsSupport=false;
        String result="";

        ServiceBook sb = ServiceBook.getSB();
        ServiceRecord[] records = sb.findRecordsByCid("IPPP");      
        if(records == null) {
            return "";
        }
       
        int numRecords = records.length;
        for( int i = 0; i < numRecords; i++ ) {
            ServiceRecord myRecord = records[i];
            String name = myRecord.getName();      
            String uid = myRecord.getUid();        

            if( myRecord.isValid() && !myRecord.isDisabled() ) {
                int encryptionMode = myRecord.getEncryptionMode();
                if( encryptionMode == ServiceRecord.ENCRYPT_RIM ) {
                    _mdsSupport = true;
                } else {
                    _bisSupport = true;
                }
            }
        }

        if( _mdsSupport ) {
            result = CON_BES;
        } else if( _bisSupport ) {
            result = CON_BIS;
        } else {
            result = CON_TCPIP;
        }
        
        return result;    
    
    }

 

 This is the line code that generates the error:

            String connectionType = Utility.getConnectionType();
            httpConnection = (HttpConnection)Connector.open(url + connectionType, Connector.READ_WRITE, true);

For BIS/BES connection that's ok, for WiFi connection I have this "random" problem.

 

Thanks.

 

Note: mdspublic is incorrect, but I can't write in this post the correct string...

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

Re: Connector - problem with WiFi

What is the detail text associated with this Exception.  You can find this using

<exception>.toString()

Contributor
Posts: 15
Registered: ‎09-02-2010
My Device: Not Specified

Re: Connector - problem with WiFi

Only "java.io.IOException".

If I remove the battery, the app work fine...

 

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

Re: Connector - problem with WiFi

Are you 100% sure it is just java.io.exception?  That is a class name, there is usually some text associated with it.  Can you show us the code where you catch and print that Exception?

 

I do suspect that there is just a short term problem with the WiFi connection on the device.  Does it also fix itself if you turn WiFi off and back on again?

Contributor
Posts: 15
Registered: ‎09-02-2010
My Device: Not Specified

Re: Connector - problem with WiFi

I have attached the device to debug (JDE 5.0.0).

 

In try catch section

} catch(Exception e) {
            hasError = true;
            error = e.toString();
            closeAll();
        }

the object "e" cannot expads, the type column is "unknown(net_rim_cldc-1,38)".

 

The type column of "error" (java.lang.String before to set e.toString() value) is "unknown(net_rim_cldc,73)", but the alt popup of this String is:

 

unknown(net_rim_cldc,73) error "java.io.IOException"

 

Only "java.io.IOException" appears in my Dialog thet print "error" String.

 

 

Contributor
Posts: 15
Registered: ‎09-02-2010
My Device: Not Specified

Re: Connector - problem with WiFi

Any idea?

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

Re: Connector - problem with WiFi

"he object "e" cannot expads, the type column is "unknown(net_rim_cldc-1,38)"."

 

This is most likely becuase your debugging environment is using a different level of OS or device to the one on the phone, so it does not know to interpret the data.

 

Can you print the String out

System.out.println(error)

to find out what the real error is in the debug log.

 

Also can you tell us what device and OS level you are testing with.  There might be an issue there, I know I had some WiFi issues with early OS's on 9000 devices for example.

 

 

Contributor
Posts: 15
Registered: ‎09-02-2010
My Device: Not Specified

Re: Connector - problem with WiFi

        } catch(Exception e) {
            hasError = true;
            error = e.toString();
            System.out.println(error);
            System.out.println(e.toString());
            System.out.println(e.getMessage());
            closeAll();
        }

The results of System.out.println are "java.io.IOException" for error and e.toString(), and nothing for e.getMessage().

 

My device info: model 9800, v6.0.0.246 (package 695, platform 6.4.0.105)

 

But I have had the same problem with others models in the past, I don't remember now these models, never I needed WiFi connenction, only BIS/BES connection.

Now, I need a WiFi connection and I have this problem...

 

I have tested it:

- remove battery, open my app, test connection: OK

- test connection after few minutes (without close the app), for many times: OK whenever

- test connection after 1 hour (without close the app): PROBLEM!!!

- close and reopen the app: PROBLEM

- remove battery: OK

 

I don't understand where is the problem... it's a random problem...