ClassCastException(在应用程序上调用UiApplication)

时间:2011-11-04 05:23:35

标签: blackberry

我收到此错误

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   

当我尝试使用

调用popUpScreen()时
UiApplication.getUiApplication()).pushGlobalScreen(new PanicPopUP(), 0, 0)//Defined in TimerDemoTask class.

BackGroundProcess类,它扩展了Application调用TimerDemoTask类,它调用上面的popUpScreen()。我尝试以这种方式强制转换Application和UiApplication

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

但仍然得到同样的例外。任何想法如何阻止这一点。

1 个答案:

答案 0 :(得分:2)

在Timertask演示类中尝试这样的.. 我认为你没有得到事件锁

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);
}

喜欢这样,看看它是否解决了你的问题......