2012-05-19 30 views
0

我想用我的攝像頭在Java中捕獲圖像在Ubuntu 11.10JMF java.util.NoSuchElementException看不到我的攝像頭

  Vector deviceList = CaptureDeviceManager.getDeviceList(new RGBFormat()); 
     System.out.println(deviceList.toString()); 
     //gets the first device in deviceList 
     device = (CaptureDeviceInfo) deviceList.firstElement(); 

我有例外 「java.util.NoSuchElementException」

我安裝JMF -2_1_1e-linux-i586.bin,我在項目中的參考庫中添加了jmf.jar。

我的攝像頭正常工作。

我應該怎麼做才能看到我的攝像頭?

感謝幫助

回答

0

請檢查矢量API,你可以看看是:

/** 
* Returns the first component (the item at index <tt>0</tt>) of 
* this vector. 
* 
* @return  the first component of this vector. 
* @exception NoSuchElementException if this vector has no components. 
*/ 
public synchronized Object firstElement() 

的DEVICELIST是空的。在調用firstElement()方法之前,應該調用isEmpty()方法。如果isEmpty()返回true,則不能調用firstElement()方法。

if(deviceList!=null && !deviceList.isEmpty()){ 
    device = (CaptureDeviceInfo) deviceList.firstElement(); 
}