0

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

}
Nevzat Günay
  • 1,039
  • 11
  • 19
  • It's a little tough to tell, is this line throwing the exception? `Tesseract instance = new Tesseract();` If so, maybe there's another constructor with arguments you can call or a factory method that returns Tesseract. – ebyrob Aug 26 '16 at 12:42
  • There is no exception for the line.Actually,when I call `tess4j-3.0.2.jar` for java project in the mirth,I get this error.However,I call `tess4j-3.2.1.jar`,I get this error as **java.lang.NoSuchFieldError: RESOURCE_PREFIX** – Nevzat Günay Aug 26 '16 at 13:22
  • All exceptions have a stack trace and exception stack traces have line numbers in them. I can't tell which line of your posted code the exception passed through based on your comments. If you downgrade tess4j, it would have to be to a pre-2.0.0 version. (upgrading everything to latest is probably recommended in any case) – ebyrob Aug 26 '16 at 13:28
  • I changed `tess4j` jar file with version 1.5,also I putted the other jar files with respect to the `tess4j-3.2.1` that it is the newest version. – Nevzat Günay Aug 26 '16 at 14:08
  • I get the new error like **Exception in thread "main" java.lang.UnsatisfiedLinkError**.Also **log4j:WARN No appenders could be found for logger (org.ghost4j.Ghostscript). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.** – Nevzat Günay Aug 26 '16 at 14:26
  • Try `instance.setDatapath("C:\\imageRAD\\Onam");` and make sure you use the correct JNA version. – nguyenq Aug 26 '16 at 15:35
  • @nguyenq I checked file path and jna version.Finally I solved the problem.I'm writing this as a solution. – Nevzat Günay Aug 29 '16 at 07:33

2 Answers2

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.

Kiskae
  • 24,655
  • 2
  • 77
  • 74
0

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.

Nevzat Günay
  • 1,039
  • 11
  • 19