我在 Mirth
中使用 Tesseract
做了一个 Java OCR
项目。当我从 Mirth 运行 jar 文件时,出现此错误当我搜索它时,我发现有一个 init() 方法,而且它是 Tesseract.java 中的一个 protected void 。我认为这可能是该错误的原因。
我该怎么办?非常感谢您的帮助。
package Tess4jTest;
import java.io.File;
import java.io.IOException;
import net.sourceforge.tess4j.*;
public class TestTess {
public static String Tc;
public static String phone;
public static String date;
public static void main(String[] args) {
//System.out.println(returnText("C:\\Users\\Nevzat\\Desktop\\deneme.pdf"));
}
public static String returnText(String fileName){
File imageFile = new File(fileName);
if(imageFile.exists()){
Tesseract instance = new Tesseract();
instance.setDatapath("C:\\imageRAD\\Onam\\tessdata");
String result = null;
try {
result = instance.doOCR(imageFile);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
if(result!=null){
int i=result.indexOf("Numarasn: ");
int j=result.indexOf("Tel No:");
int k=result.indexOf("Bilgllendirme Tarihl:");
Tc = result.substring(i+10, i+21);
phone = result.substring(j+8,j+23);
date = result.substring(k+22,k+32);
//System.out.println(result);
}else{
return "Null Error!";
}
}else{
return "Does not found a file!";
}
return Tc+","+phone+","+date;
}
public static String returnTC() throws IOException{
return Tc;
}
public static String returnPhone() throws IOException{
return phone;
}
public static String returnDate() throws IOException{
return date;
}
}
最佳答案
当您尝试使用私有(private)构造函数创建对象时,会出现错误。 ( <init>()
是不带参数的构造函数的名称)
查看 tess4j
来源我找到了一个具有以下文档的方法:
- @deprecated As of Release 2.0, use default constructor instead.
查看 2.0 之前的源代码,发现默认构造函数是私有(private)的。
这意味着您的问题很可能是针对高于 2.0 的版本进行编译,但您的环境正在运行早于 2.0 的版本。
更新您的环境或降级您构建的库来修复它。
关于java.lang.IllegalAccessError : tried to access method net. sourceforge.tess4j.Tesseract.<init>()V 来自类 Tess4jTest.TestTess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164580/