ClassCastException on BarCodeReader


#1

I’ve a multi-page TIFF image with bar codes in few pages. I have iterated over all pages with one bufferedImage at a time.

The following code snippet throws ClassCastException:
ImageInputStream is = ImageIO.createImageInputStream(new File(imagePath));
javax.imageio.ImageReader reader = iterator.next();

           reader.setInput(is);
           int numberOfPages = reader.getNumImages(true);
         
           BarCodeReader bcreader;
         
           for (int i = 0; i < numberOfPages; i++) {
                 try {
                 
                // Load page to BufferedImage
                 buffered = reader.read(i);
                 bcreader = new BarCodeReader(buffered, DecodeType.CODE_128); //Exception here

                 while(bcreader.read())
                 {
                        System.out.println("    BarCode CodeText: " + bcreader.getCodeText());
                 }
                 bcreader.close();
           }

Stacktrace:
java.lang.ClassCastException: [S cannot be cast to [B
** at java.awt.image.MultiPixelPackedSampleModel.getDataElements(Unknown Source)**
** at java.awt.image.Raster.getDataElements(Unknown Source)**
at com.aspose.barcode.internal.gl.a.a(Unknown Source)
at com.aspose.barcode.internal.gl.a.a(Unknown Source)
at com.aspose.barcode.internal.gy.e.a(Unknown Source)
at com.aspose.barcode.internal.gy.e.write(Unknown Source)
at javax.imageio.ImageWriter.write(Unknown Source)
at com.aspose.barcode.internal.ew.a.a(Unknown Source)
at com.aspose.barcode.internal.ew.a.b(Unknown Source)
at com.aspose.barcode.internal.ew.a.b(Unknown Source)
at com.aspose.barcode.internal.ew.a.a(Unknown Source)
at com.aspose.barcode.internal.dl.b.a(Unknown Source)
at com.aspose.barcode.internal.dl.x.a(Unknown Source)
at com.aspose.barcode.internal.dl.x.a(Unknown Source)
at com.aspose.barcode.internal.dl.x.a(Unknown Source)
at com.aspose.barcode.internal.mf.g.a(Unknown Source)
at com.aspose.barcode.barcoderecognition.BarCodeReader.setBarCodeImageInternal(Unknown Source)
at com.aspose.barcode.barcoderecognition.BarCodeReader.(Unknown Source)
at com.aspose.barcode.barcoderecognition.BarCodeReader.(Unknown Source)

I also have referenced the article below:

Appreciate any clues.
Thanks!


#2

@swathip,
Please share your sample file with us for our testing. We will reproduce the problem and provide our feedback after analysis.