2010-11-19 82 views
0

我使用jde 4.5希望通过我的应用程序使用相机。 我写的代码和得到运行时exceletion Pushmodelscreen由非事件线程caled 告诉我它的问题是什么?启动相机问题?

公共无效启动照相机()

{ 
    try { 
// Create a player for the Blackberry's camera 
Player player= Manager.createPlayer("capture://video"); 
    // Set the player to the REALIZED state (see Player javadoc) 
     player.realize(); 
     // Grab the video control and set it to the current display 
     _videoControl = (VideoControl)player.getControl("VideoControl"); 
     if (_videoControl != null) 
     { 
      // Create the video field as a GUI primitive (as opposed to a 
      // direct video, which can only be used on platforms with 
      // LCDUI support.) 
      _videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field"); 
      _videoControl.setDisplayFullScreen(true); 
      _videoControl.setVisible(true); 
     } 
     player.start(); 
     if(_videoField!=null) 
     { 
     add(_videoField); 
     } 

}赶上(例外五){// TODO:处理异常 Dialog.alert(e.getMessage()); }} `

thnaks很多 阿米特

+0

'Pushmodelscreen caaled by non event thread' 这个错误通常发生在弹出屏幕或'Dialog.alert'需要在任何屏幕被推动之前显示。 – Prasham 2010-11-19 11:01:42

回答

0

的代码,参与UI的改变应该从UI线程中调用。因此,最有可能你的代码的某些部分应该叫的方式:

UIApplication.getUiApplication().invokeLater(new Runnable() { 
    public void run() { 
     // do your UI related staff here 
     // e.g. push a Screen or call Dialog.alert(), etc. 
    } 
}); 

此外,您可能会发现this info有趣。