Null Pointer Exception in using OCR for Java


#1

Hi Concern


I am getting the following error when run my program .
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.aspose.ocr.ILanguage;
import com.aspose.ocr.ImageStream;
import com.aspose.ocr.Language;
import com.aspose.ocr.OcrEngine;
//import com.aspose.ocr.ResourcesSource;
public class OCR {
public static String myDir = “c:/temp/”;
public static void main(String args[])
{
// Set the paths
String imagePath = “C:/Documents and Settings/aashish.kumar/Desktop/3.jpg”;
String resourcesFolderPath = “C:/Documents and Settings/aashish.kumar/Desktop/resources.zip”;

// Create an instance of OcrEngine
OcrEngine ocr = new OcrEngine();
// Set Resources for OcrEngine
try {
ocr.setResource(new FileInputStream(resourcesFolderPath));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Set NeedRotationCorrection property to false
ocr.getConfig().setNeedRotationCorrection(false);

// Set image file
ocr.setImage(ImageStream.fromFile(imagePath));

// Add language
ILanguage language = Language.load(“english”);
ocr.getLanguages().addLanguage(language);

// Perform OCR and get extracted text
try {
if (ocr.process()) {
System.out.println("\ranswer -> " + ocr.getText());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}



And I get the Error as:

java.lang.NullPointerException
at com.aspose.internal.ocr.bm.b.b(Unknown Source)
at com.aspose.internal.ocr.bj.c.a(Unknown Source)
at com.aspose.ocr.OcrEngine.a(Unknown Source)
at com.aspose.ocr.OcrEngine.process(Unknown Source)
at OCR.main(OCR.java:37)

Om Windows XP service pack 2
Please help me

Aashish Kumar.

#2

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.