Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:00:03+00:00 2026-05-29T10:00:03+00:00

I was hoping someone would be able to help me with a problem I’ve

  • 0

I was hoping someone would be able to help me with a problem I’ve been having with an application I’m developing that makes use of a webcam in java with JMF media library.

The problem I am having is I can run the webcam ok in an application by itself with this class here

import java.awt.BorderLayout;
import java.util.Vector;

import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FormatControl;
import javax.swing.JFrame;
import javax.swing.JButton;

public class WebcamClass{

CaptureDeviceInfo cam;
MediaLocator locator;
Player player;
FormatControl formatControl;
public WebcamClass(){

    try{
                    // List out available Devices to Capture Video.
        Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList ( null );
                    System.out.println(list);
        // Iterating list
        for(CaptureDeviceInfo temp : list){
            // Checking whether the current device supports VfW
            // VfW = Video for Windows
                        if(temp.getName().startsWith("vfw:"))
                        {
            System.out.println("Found : "+temp.getName().substring(4));
            // Selecting the very first device that supports VfW
            cam = temp;
            System.out.println("Selected : "+cam.getName().substring(4));
            break;
                        }
        }

        System.out.println("Put it on work!...");
        // Getting the MediaLocator for Selected device.
        // MediaLocator describes the location of media content
        locator = cam.getLocator();

        if(locator != null){

            // Create a Player for Media Located by MediaLocator
            player = Manager.createRealizedPlayer(locator);

            if(player != null){

                // Starting the player
                player.start();

                // Creating a Frame to display Video
                                    JFrame f = new JFrame();
                f.setTitle("Test Webcam");

                f.setLayout(new BorderLayout());
                // Adding the Visual Component to display Video captured by Player
                // from URL provided by MediaLocator
                f.add(player.getVisualComponent(), BorderLayout.CENTER);
                f.pack();
                f.setVisible(true);
            }

        }

    }catch(Exception e){
        System.out.println(e);
    }
}

}

However when I put it into my GUI application where I would like to run it from I keep getting “Exception in thread “AWT-EventQueue-0″ java.lang.NullPointerException” when i press the button to turn the camera on.

I know it isn’t picking up the webcam device but i can’t understand why as it does when i’m not trying to embed it in my GUI.

I have the JMF.jar in my libraries folder as well.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:00:04+00:00Added an answer on May 29, 2026 at 10:00 am

    Without more info on your NullPointerException it is impossible to say what is causing the problem. In the stack trace for the exception, you should identify the line in the code you wrote that triggers the exception.
    Without any more information, my guess is you don’t have an ActionListener registered to the JButton that should start the camera.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am hoping that someone can help me with a problem I've got at
I am hoping that someone can help me with this relative simple problem: <?php
I'm having with some margin or padding issues with IE8 that I'm hoping someone
OK, I've not been able to figure this out thus far. Hoping someone can
Background: I have a design pattern problem that I was hoping someone may be
I was hoping someone that is good with math and loops could help me
I'm having a problem with the WPF Tab View control that I was hoping
I'm having trouble with one particular issue, I was hoping someone could help me
I am having trouble writing a sql query and I was hoping that someone
Hoping that someone here will be able to provide some mysql advice... I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.