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
Regular Contributor
Posts: 52
Registered: ‎10-31-2010
My Device: Not Specified
My Carrier: developer
Accepted Solution

Illegal state exception while reading MCC

Hi,

I'm using the above method to read MCC


    private void readMCC() {
        log("reading mcc");
        int mccInt = RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex());
        log("mcc" + Integer.toString(mccInt));
        mcc = Integer.toHexString(mccInt);
        log("mcc" + mcc);
       
    }
It's working fine for the first time after installation. If i restart my phone it's throwing illegal state exception .

But i'm get printed current network index correctly.

Can anybody help me to resolve this ?

Thanks in advance.
Developer
Posts: 16,795
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Illegal state exception while reading MCC

it may be possible that the network is not available at startup resp. by the time you execute this code.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Regular Contributor
Posts: 52
Registered: ‎10-31-2010
My Device: Not Specified
My Carrier: developer

Re: Illegal state exception while reading MCC

Thanks Simon,

But me too guess the same. Though when i printed RadioInfo.getCurrentNetworkIndex() separately it's 

get printed as 0 without any exceptions.

 

Printing zero , will it mean no RadioInfo thr ?

 

How can i solve this ?

 

Thanks in advance.

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

Re: Illegal state exception while reading MCC

[ Edited ]

Here is a good pattern for 'start-up' processing that should mean you can get your Radio information once the device has properly started. 

 

http://supportforums.blackberry.com/t5/Java-Development/Write-safe-initialization-code/ta-p/444795

Developer
Posts: 16,795
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Illegal state exception while reading MCC

while peters suggestion is of course valid it does not solve the problem.

some people have devices which connect only after a prompt, or the user needs to start the network manually.

 

i would suggest that you check http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/system/RadioInfo.html#getNumbe... first, and if there are none register a radiostatuslistener (which you most likely have anyhow to get notified about mcc changes)

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 52
Registered: ‎10-31-2010
My Device: Not Specified
My Carrier: developer

Re: Illegal state exception while reading MCC

Thanks a lot Peter & Simon for the sugesstions Smiley Happy.

 

Peter's suggesstion worked well.

 

Thanks again

Regular Contributor
Posts: 52
Registered: ‎10-31-2010
My Device: Not Specified
My Carrier: developer

Re: Illegal state exception while reading MCC

There an iterface RadiStateListner to listen , when the status change. Am i right ?

Hope using that i can resolve this issue.

 

Hence i'm using some other methods also needs to iniialize i think it's better to use systemListner as Peter suggested.

 

Thanks.

Regular Contributor
Posts: 52
Registered: ‎10-31-2010
My Device: Not Specified
My Carrier: developer

Re: Illegal state exception while reading MCC

Hi,


I'm reading MCC when application in auto startup

mcc =Integer.toHexString(RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex()));


Previously i got illegal state exception and now it is no longer existing after setting the system listeners.

But still i'm getting null value and illegalArgumentException.


I have tried by setting RadiStatusListeners as well.But didn't work.


Can anyboday help me on this ?


It's urgent Smiley Sad

 

Thanks in advance.