Hello, im new in this forum and programming in java, and i have a problem:
at school we are programming this code to initialize the webcam and show it on the screen, but it doesn´t work :C this is a code that did run in another computer, but i cant see what's wrong with it . My webcam does work good, and the driver is already installed. Hope you can help me, im a noob u.u. Here is the code:
package webcam;
import java.awt.BorderLayout;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.Processor;
import javax.swing.JFrame;
public class Webcam extends JFrame {
private static Player player;
private MediaLocator localizador;
private Processor p;
private CaptureDeviceInfo dispositivo=null;
private static String source="vfw:Microsoft WDM Image Capture (Win32):0";
public Webcam(){
setLayout(new BorderLayout());
setSize(500,400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Camara Web");
player=null;
localizador=null;
dispositivo=CaptureDeviceManager.getDevice(source) ;
localizador=dispositivo.getLocator();
iniciarCaptura();
}
private void iniciarCaptura(){
try{
player=Manager.createRealizedPlayer(localizador);
player.start();
if(player.getVisualComponent()!=null){
add(player.getVisualComponent(), BorderLayout.CENTER);
}
}
catch(Exception e){
System.err.println(e.toString());
}
}
public static void main(String[] args) {
Webcam camara=new Webcam();
Webcam.setDefaultLookAndFeelDecorated(true);
camara.setVisible(true);
}
}
//THE ERROR IS THE NEXT ONE
Exception in thread "main" java.lang.NullPointerException
at webcam.Webcam.<init>(Webcam.java:35)
at webcam.Webcam.main(Webcam.java:53)
Java Result: 1
please help! :C