Error in Java, "Can not inherit from final class error"

1

I get this error, I'm using some zxing libraries.

java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

The code that I execute is the following:

public static void main(String[] args) {
    InputStream barCodeInputStream;
    try {
        String IMG_PATH = "Ruta:\imagen.png";
        barCodeInputStream = new FileInputStream(IMG_PATH);
        BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);

       // LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
       BufferedImageLuminanceSource  source = new BufferedImageLuminanceSource(barCodeBufferedImage);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        Reader reader = new MultiFormatReader();
        Result result = reader.decode(bitmap);


        System.out.println("Barcode text is " + result.getText());

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

I think it falls on the next line:

BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

That class contains the following:

public final class BinaryBitmap {

   private final Binarizer binarizer;
   private BitMatrix matrix;

   public BinaryBitmap(Binarizer binarizer) {
       if (binarizer == null) {
          throw new IllegalArgumentException("Binarizer must be non-null.");
       }
       this.binarizer = binarizer;
   }

And more methods.

Edit 2:

The Binarizer class:

public abstract class Binarizer {

  private final LuminanceSource source;

  protected Binarizer(LuminanceSource source) {
     this.source = source;
  }

  public final LuminanceSource getLuminanceSource() {
     return source;
  }

  public final int getWidth() {
     return source.getWidth();
  }

  public final int getHeight() {
     return source.getHeight();
  }

}
    
asked by Victor Armas 28.04.2017 в 18:28
source

1 answer

0

I found the problem. I had added several ZXing libraries, and in two of them, I had classes with the same name and the same route, that class was GlobalHistogramBinarizer, in one of the libraries this class was declared as final class, and in another library it was not. And the HybridBinarizer class was extending from it, and pointed to the class of the library in which GlobalHistogramBinarizer was declared as the final class. Thanks to @ SJuan76 for helping me. Greetings!

    
answered by 16.07.2017 / 22:28
source