TestTess访问方法net

TestTess访问方法net

本文介绍了java.lang.IllegalAccessError:尝试从类Tess4jTest.TestTess访问方法net.sourceforge.tess4j.Tesseract.< init>()V的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mirth中用Tesseract做了一个Java OCR项目.当我从Mirth运行jar文件时,出现此错误.当我搜索它时,发现有一个init()方法.而且它在Tesseract.java中是一个受保护的空位.我认为这可能是该错误的原因.我该怎么办?非常感谢您的帮助.

I did a Java OCR project with Tesseract in the Mirth.When I run the jar file from the Mirth,I get this error.When I search it,I found that there is a init() method and also it is a protected void in Tesseract.java.I think that maybe it is the reason for that error.What should I do?Thank you so much for your helps.

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;
}

}

推荐答案

当您尝试使用私有构造函数创建对象时,会发生错误. (<init>()是没有参数的构造函数的名称)

The error you got occurs when you try to create an object with a private constructor. (<init>() is the name of a constructor with no parameters)

tess4j源代码中,我找到了具有以下文档的方法:

Looking at the tess4j source I found a method with the following documentation:

在2.0之前的源代码中发现默认构造函数是private.

Looking at the source before 2.0 reveals the default constructor was private.

这意味着您的问题很可能是针对2.0版以上的版本进行编译的,但是您的环境运行的是2.0版之前的版本.

This means your problem is most likely that you are compiling against a version newer than 2.0, but your environment is running one older than 2.0.

要么更新您的环境,要么降级您​​要构建的库以对其进行修复.

Either update your environment or downgrade the library you build against to fix it.

这篇关于java.lang.IllegalAccessError:尝试从类Tess4jTest.TestTess访问方法net.sourceforge.tess4j.Tesseract.&lt; init&gt;()V的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:30