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
Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified
Accepted Solution

Clas cast trying to get UI Application

Greetings

 

I have been running my code fine on the version 5 simulators. I just bought a bold 9900 and my program was failing on it. So I got the sumilator (running 7.0) and I am getting a ClassExceptionCast when the following call is made

 

        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {

 

It is actually on the call to

 

UiApplication.getUiApplication().

 

I thought thay maybe it was null and I was trying to offset ti so I went

 

UiApplication application = UiApplication.getUiApplication();

 

And still got the cast class exception there.

 

Any ideas as to what I might be doing wrong?

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

Re: Class cast trying to get UI Application

Can you tell me what 'environment' you code is actually running in?  Is it something like a system listener?

Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified

Re: Class cast trying to get UI Application

It happens in the context of a PlayerListener public void playerUpdate(Player player, String event, Object eventData) {
Developer
Posts: 16,679
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Class cast trying to get UI Application

it may be possible that the listener is executed in the context of another application.
i would suggest that you call getApplication and check what class is returned there.

I know this behavior mainly from the phone listener, we use global events there to pass the event to the main application.
----------------------------------------------------------
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
Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified

Re: Class cast trying to get UI Application

It throws exception just doing this Object obj = UiApplication.getUiApplication(); I did as you suggested and just made a static global of the application when app starts, however, that even returned null. So what I had to do was pass the instance of the app to my main screen app (the one that finally receives the listener callback) and call it from there. It could not be static - it had to be a class member.