nguyenq / tess4j

Java JNA wrapper for Tesseract OCR API
Apache License 2.0
1.61k stars 373 forks source link

How to build a correct jar with JDK7 #197

Closed jokwei closed 4 years ago

jokwei commented 4 years ago

Hello, when I built a demo jar with tess4j v4.0.0 and JDK7, there had mistakes as below:

ERROR net.sourceforge.tess4j.Tesseract - null java.lang.NullPointerException: null at net.sourceforge.tess4j.util.ImageIOHelper.convertImageData(ImageIOHelper.java:312) at net.sourceforge.tess4j.util.ImageIOHelper.getImageByteBuffer(ImageIOHelper.java:302) at net.sourceforge.tess4j.Tesseract.setImage(Tesseract.java:394) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:287) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:209) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:193) at main.java.com.jo.tesseract.Main.main(Main.java:65) net.sourceforge.tess4j.TesseractException: java.lang.NullPointerException at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:193) at main.java.com.jo.tesseract.Main.main(Main.java:65) Caused by: java.lang.NullPointerException at net.sourceforge.tess4j.util.ImageIOHelper.convertImageData(ImageIOHelper.java:312) at net.sourceforge.tess4j.util.ImageIOHelper.getImageByteBuffer(ImageIOHelper.java:302) at net.sourceforge.tess4j.Tesseract.setImage(Tesseract.java:394) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:287) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:209)

I found this commit whick might fixed this NPE: Fix for BufferedImage OCR #134. So I guessed I have to update my tess4j version. However once I updated to v4.5.3, problem solved, but project required JDK8.

Does here any solution for NPE and JDK7 ?

nguyenq commented 4 years ago

You can view the history and determine which version of Tess4J was last built using JDK 7.

Or you can clone the repository and modify the source until it builds successfully with JDK 7.

jokwei commented 4 years ago

tess4j v4.3.1 was last built using JDK7, and it was correct without NPE. Thanks for your helpšŸ—