Bar Code Recognition

I just bought the license for bar code using Java
When i run it in desktop application in a developer machine then i am getting the following message

Exception in thread “main” class com.aspose.pdf.exceptions.IndexOutOfRangeException: At most 4 elements (for any collection) can be viewed in evaluation mode.

How can i be in evaluation mode while i bought the license and installed it using the following code
com.aspose.barcode.License barcodeLicense = new com.aspose.barcode.License();
InputStream fs = new FileInputStream(getAsposeBarecodeLicensePath());
barcodeLicense.setLicense(fs);

@sd4it

It seems that you are encountering an IndexOutOfRangeException indicating that your application is still in evaluation mode, despite having purchased a license for Aspose.BarCode. This issue typically arises when the license is not applied correctly.

Here are some steps to troubleshoot and ensure that the license is applied properly:

  1. Verify License File Path: Ensure that the path to your license file is correct. The method getAsposeBarecodeLicensePath() should return the exact path where your license file is located.

  2. Check License Application Code: Make sure that you are applying the license correctly in your code. Here’s a sample code snippet that demonstrates how to apply the license from a file stream:

    import com.aspose.barcode.License;
    import java.io.FileInputStream;
    import java.io.InputStream;
    
    public class LicenseApplication {
        public static void main(String[] args) {
            try {
                License barcodeLicense = new License();
                InputStream fs = new FileInputStream("path/to/your/Aspose.BarCode.Java.lic");
                barcodeLicense.setLicense(fs);
                System.out.println("License applied successfully.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
  3. Check for Exceptions: Ensure that there are no exceptions being thrown when you attempt to apply the license. If there are issues with the license file itself (e.g., it is corrupted or not valid), it may not be applied correctly.

  4. Run in the Correct Environment: Make sure that you are running your application in the same environment where the license file is accessible. If you are using an IDE, ensure that the working directory is set correctly.

  5. Rebuild the Project: Sometimes, changes may not take effect until the project is rebuilt. Try cleaning and rebuilding your project to ensure that all changes are applied.

If you follow these steps and still encounter issues, please provide additional details about your setup, and I can assist you further.

Sources:
[1]: Apply License From Stream Example

I tried what you said and it says license is applied successfully but still i am getting the same error afterwards

Here is the complete code

private static void detectBarCode()
throws Exception
{
License barcodeLicense = new License();
InputStream fs = new FileInputStream(“c:\erp\Aspose.BarCode.Java.lic”);
barcodeLicense.setLicense(fs);
System.out.println(“License applied successfully.”);

String file = "D:\\mytemp\\sample_barcode.pdf";

com.aspose.pdf.Document pdfDoc = new com.aspose.pdf.Document(file);

for (int i = 1; i <= pdfDoc.getPages().size(); ++i)
{
  byte[] ms = pdfDoc.getPages().get_Item(i).convertToPNGMemoryStream();
  InputStream stream = new ByteArrayInputStream(ms);

  BarCodeReader reader = new BarCodeReader(stream);

  for (BarCodeResult result: reader.readBarCodes())
  {
    System.out.println("Page Number: " + i);
    System.out.println("CodeText: " + result.getCodeText());
    System.out.println("Symbology type: " + result.getCodeType());
    System.out.println(("-------------------------------"));
    break;
  }
}

}

i resolved the issue
i am posting the solution here

JRE detects XML parser from Oracle XML library xmlparserv2.jar as default. Oracle parser doesn’t support features required by log4j.

It is possible to force JRE to use default XML parser from JRE

  • Either; System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
  • or use -D runtime param; -Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

@sd4it,

Thanks for the sharing the solution and good to know that you have sorted out your issue. Please don’t hesitate to reach out if you have any other questions or feedback.