我试过在Eclipse中使用Tess4J,但结果导致标题错误。我导入了以下jar文件:tess4j,jai_imageio和jna。我编写的测试代码按照其示例页面上给出的示例进行。

                File DMTfile = new File(System.getProperty("user.dir")+"\\DMTcap.bmp");
                BufferedImage DMTcap = ImageIO.read(DMTfile);Tesseract instance = new Tesseract();

                String result = "";
                try {
                    result = instance.doOCR(DMTcap);
                } catch (TesseractException e2) {
                    e2.printStackTrace();
                }
                System.out.println(result);


完整错误如下:

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: RESOURCE_PREFIX
at net.sourceforge.tess4j.util.LoadLibs.<clinit>(Unknown Source)
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
at net.sourceforge.tess4j.Tesseract.init(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at DMT$10.actionPerformed(DMT.java:516)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


我怎样才能解决这个问题?

最佳答案

Platform.RESOURCE_PREFIX是JNA常量。确保使用适当版本的JNA(4.1.0)。

还要检查这篇文章中的答案:NoSuchFieldError: RESOURCE_PREFIX with a maven project using tess4j

关于java - NoSuchFieldError:将Tess4J与Eclipse一起使用时,RESOURCE_PREFIX,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33080638/

10-08 21:54