Reading QR code using Webcam in Java

i am writing a code to read QR code in java (Netbeans IDE) using Webcam, the code was free from syntax error but the code refuse to build. The code is use is: -

Webcam webcam = Webcam.getDefault();;

Result result = null;
BufferedImage image = null;

if (webcam.isOpen()) {
//if ((image = webcam.getImage()) == null) {

LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
result = new MultiFormatReader().decode(bitmap);
} catch (ReaderException e) {


if (result != null) {
System.out.println("QR code data is: " + result.getText());

The error is: -

java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(
at java.lang.Class.privateGetMethodRecursive(
at java.lang.Class.getMethod0(
at java.lang.Class.getMethod(
at sun.launcher.LauncherHelper.validateMainClass(
at sun.launcher.LauncherHelper.checkAndLoadMain(
Error: A JNI error has occurred, please check your installation and try again
Exception in thread “main” C:\Users\jh\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1

Please how do i resolve this error. thank you

Some clarification about the error message you are getting:

Also, next time please post your code or console output inside a code block or a GitHub Gist ( That makes it a bit easier for all of us.

1 Like