jeremycrosbie / barcode4j

Fork of the barcode4j library from http://barcode4j.sourceforge.net/
Apache License 2.0
17 stars 12 forks source link

Barcode ITF14 not working (IllegalAccessError) #2

Open clairtonluz opened 8 years ago

clairtonluz commented 8 years ago

I'am using Oracle JDK 8u77 and when I try call the method ITF14Bean.generateBarcode(canvas, number) I get this exception:

java.lang.IllegalAccessError: tried to access field org.krysalis.barcode4j.impl.DefaultCanvasLogicHandler.bcBean from class org.krysalis.barcode4j.impl.int2of5.ITF14CanvasLogicHandler

    at org.krysalis.barcode4j.impl.int2of5.ITF14CanvasLogicHandler.getITF14Bean(ITF14CanvasLogicHandler.java:42)
    at org.krysalis.barcode4j.impl.int2of5.ITF14CanvasLogicHandler.startBarcode(ITF14CanvasLogicHandler.java:48)
    at org.krysalis.barcode4j.impl.int2of5.Interleaved2Of5LogicImpl.generateBarcodeLogic(Interleaved2Of5LogicImpl.java:181)
    at org.krysalis.barcode4j.impl.int2of5.ITF14Bean.generateBarcode(ITF14Bean.java:124)

below my code:

public InputStream gerar(String number) {
    File outputFile = new File("out.jpg");
    final int dpi = 150;

    ITF14Bean bean = new ITF14Bean();
    bean.setHeight(32);
    bean.setModuleWidth(1);
    bean.setWideFactor(2.5);
    bean.setChecksumMode(ChecksumMode.CP_AUTO);
    bean.setBearerBarWidth(0);
    bean.setBearerBox(false);

    OutputStream out = new FileOutputStream(outputFile);
    try {
      BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, "image/jpeg", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);

      bean.generateBarcode(canvas, number);
      canvas.finish();
    } finally {
      out.close();
    }

    return new FileInputStream(outputFile);
}
pinheiroras1 commented 7 years ago

Hi my friend,

use compile 'net.sf.barcode4j:barcode4j-fop-ext:2.1'

:+1: