Search code examples
blackberry

ClassCastException (Invoking UiApplication on Application)


I am getting this error

Thread [TimerDemo(185)id=307040256] (Suspended (exception ClassCastException))  
UiApplication.getUiApplication() line: 462  
TimerDemoTask$1.run() line: 18  
BackGroundProcess(Application).dispatchInvokeLater(Runnable, Object, int) line: 1456    
BackGroundProcess(Application).doProcessNextMessage(Message) line: 2088 
BackGroundProcess(Application).processNextMessage(Message) line: 1530   
BackGroundProcess(Application).enterEventDispatcher() line: 1371    
TimerDemo.main(String[]) line: 15   

when I am trying to call a popUpScreen() using,

UiApplication.getUiApplication()).pushGlobalScreen(new PanicPopUP(), 0, 0)//Defined in TimerDemoTask class.

BackGroundProcess class which extends Application calls TimerDemoTask class which invokes popUpScreen() as above. I tried to cast Application and UiApplication in this way

((UiApplication)Application.getApplication()).pushGlobalScreen(new TimerDemoPopupScreen(),0,0);

but still getting the same exception.Any idea how to impelement this.


Solution

  • Try like this in your Timertask demo class.. i think you are not getting the eventlock

    synchronized (getEventLock()) {
    
        //with this UiEngine pushGlobal dialogs
    
        //whenever with the app in background
    
        UiEngine ui = Ui.getUiEngine();
        ui.pushGlobalScreen(new TimerDemo(), 1, UiEngine.GLOBAL_QUEUE);
    }
    

    like this and see if it solved your issue ....