0

我想在 ubuntu 11.10 上使用我的网络摄像头在 Java 中捕获图像

         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。

我的网络摄像头正常工作。

我应该怎么做才能看到我的网络摄像头?

感谢您的帮助

4

1 回答 1

0

Please check the Vector API, you can look that:

/**
 * 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()

The deviceList is empty. You should call the isEmpty() method before calling the firstElement() method. If the isEmpty() return true, you can't call the firstElement() method.

if(deviceList!=null && !deviceList.isEmpty()){
    device = (CaptureDeviceInfo) deviceList.firstElement();
}
于 2012-05-19T15:21:31.393 回答