java.lang.IllegalAccessError: tried to access method net.sourceforge.tess4j.Tesseract.<init>()V from class Tess4jTest.TestTess

岁酱吖の 提交于 2020-01-25 09:13:05

问题


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

}

回答1:


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)

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

  • @deprecated As of Release 2.0, use default constructor instead.

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

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.




回答2:


I solved the error and have finished the project.I mention step by step

1.You have to use right jar files for tess4j.

2.Add java project all of in the tess4j-3.2.1.zip except tess4j-3.2.1.jar via Build Path.

3.Add tess4j-1.5.jar from this

4.Add tessdata folder,ghost4j-0.5.1.jar,jna-4.1.jar,tess4j.jar and jar file of your java project.



来源:https://stackoverflow.com/questions/39164580/java-lang-illegalaccesserror-tried-to-access-method-net-sourceforge-tess4j-tess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!