Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile time error #69

Closed
vinodcbe opened this issue Mar 16, 2013 · 21 comments
Closed

Compile time error #69

vinodcbe opened this issue Mar 16, 2013 · 21 comments
Labels

Comments

@vinodcbe
Copy link

Hi i downloaded the jar files you specified and included all the jar files into my project and complied the TestPictureExample. I get an error saying create new class for Webcam. What can i do? Should Actually i complied it using netbeans. Should i have to use another source to run this code?

@sarxos
Copy link
Owner

sarxos commented Mar 16, 2013

Can you please provide the error you got?

It doesn't matter of which IDE are you using - this can be Eclipse, Netbeans or IntelliJ, it's enough to add webcam-capture-[version].jar to the classpath together with all dependencies from libs directory (you can find both in ZIP file).

If you are using Maven, you don't have to add those files to classpath. Just include <dependency> in your pom.xml - for details on artifactId and groupId see README.md file in project's root directory. Same for Gradle and/or Ivy, dependency will be the same.

@vinodcbe
Copy link
Author

Ya i have added those jar files as you said. It prompts us to "create new class for Webcam"

@sarxos
Copy link
Owner

sarxos commented Mar 16, 2013

Which Webcam Capture version and IDE are you using?

@vinodcbe
Copy link
Author

Webcam capture version 0.3.9 and netbeans version 7.2.1

@He-Pin
Copy link

He-Pin commented Mar 16, 2013

paste your test code here,so we could have a look~

@sarxos
Copy link
Owner

sarxos commented Mar 16, 2013

Version 0.3.9 has been tested many times, and no one reported missing classes. The problem you are describing appears probably because Netbeans is not able to find Webcam class and there are several reasons why this can happening:

  • Webcam Capture JAR is not in the classpath,
  • You are using Java 1.4 or 1.5 - the minimum Java version for Webcam Capture is 1.6,
  • Webcam Capture JAR is broken and Java is not able to read it. The SHA1 digest for this JAR is d324f07afdd4f6fd0884925da9b8702cb121d757, you can verify if it is correct by calculating SHA1 from it. In all cases you can download it from Maven Central by clicking on this link.

@vinodcbe
Copy link
Author

So what can i do for that? How can i make it work?

@vinodcbe
Copy link
Author

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class TakePictureExample {

public static void main(String[] args) throws IOException {

    // automatically open if webcam is closed
    Webcam.setAutoOpenMode(true);

    // get image
    BufferedImage image = Webcam.getDefault().getImage();

    // save image to PNG file
    ImageIO.write(image, "PNG", new File("test.png"));
}

}
This is the code i compiled

@sarxos
Copy link
Owner

sarxos commented Mar 16, 2013

  1. Check which Java version you are using in Netbeans. This should be somewhere in configuration. It should be 1.6 or 1.7, and 1.5 will cause the problems.
  2. Check if SHA1 of your JAR is the same as I posted above, download JAR directly from Maven repository. You can use some online tool to calculate SHA1 from file.

I use Eclipse, not Netbeans, so if you switch to Eclipse I can send you working project if above won't help. You will just have to import it and add your own code. If you have lower Java version (e.g. 1.5), I can build new release for you. But first we need to figure out what is wrong within your configuration that cause described problem.

@sarxos
Copy link
Owner

sarxos commented Mar 16, 2013

The last thing, if anything help, is to simply to copy whole Webcam Capture source code and drop it into your project.

Ok, I have to left you guys for a while since I have a regular band meeting today to practice a little bit. I will be back in several hours. Please let me know about your findings.

@sarxos
Copy link
Owner

sarxos commented Mar 16, 2013

There is a missing import at the start of your source file. You should add:

import com.github.sarxos.webcam.Webcam;

@vinodcbe
Copy link
Author

We are using JDK1.6. And i downloaded the jar file u mentioned and i am still getting that same error saying "create a new class for webcam" .

@He-Pin
Copy link

He-Pin commented Mar 16, 2013

The Webcam class is not auto imported in to your java file.just import it~using eclipse and idea will make your life easier .

@sarxos
Copy link
Owner

sarxos commented Mar 17, 2013

@v3v3v3

Does problem still exists after you add this line in your file imports?

import com.github.sarxos.webcam.Webcam;

@sarxos
Copy link
Owner

sarxos commented Mar 17, 2013

Hi,

At the link below you can find configured Eclipse project with working example you've provided:

http://sarxos.pl/download/webcam-capture-project.zip

That's all I can do in terms of this issue. If you still observe described problem, please check imports and review your Netbeans configuration.

@sarxos sarxos closed this as completed Mar 17, 2013
@vinodcbe
Copy link
Author

HI i actually run the TakePictureExample program. Java can't recognise the Webcam class so it prompts me to create new class for Webcam.

@He-Pin
Copy link

He-Pin commented Mar 18, 2013

....It's so strange~!

@sarxos
Copy link
Owner

sarxos commented Mar 18, 2013

Ok, please notice that TakePictureExample is originally located in com.github.sarxos.webcam package, so it does not need import because Webcam class is in the same package. Java does not force you to import classes within the same package (same here means simply that it has the same name).

Example (this will compile without any problems):

package boo.foo;

public class A {
}
package boo.foo;

public class B {
  public void main(String[] args)  {
    A var = new A();
  }
}

But when you move B to a different package (it was boo.foo, now we move it to (default), that is no package):

public class B {
  public void main(String[] args)  {
    A var = new A();
  }
}

This will cause error - class A not found. That's because it's not in the same package and there is no import.

@sarxos
Copy link
Owner

sarxos commented Mar 18, 2013

I will move all examples from com.github.sarxos.webcam to com.github.sarxos.webcam.example, so all imports will be automatically updated. This should not confuse users any more.

@vinodcbe
Copy link
Author

the suggestions which u guys gave were very useful. our program is working properly :) :) 👍 👍 thanks a lot :)

@Dejiola
Copy link

Dejiola commented Oct 30, 2016

Hi, I want my program to take a snapshot using webcam, save it and load the image subsequently. But each time I run the program, the previous image saved is always loaded as the current image cannot be loaded until the project directory is refreshed. I am using eclipse. My question is how can my current image be recognised? The image file is saved as "test.jpg"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants