簡體   English   中英

Tess4J InvocationTargetException

[英]Tess4J InvocationTargetException

我在Eclipse編譯器之外運行以下Java代碼時遇到問題。 在編譯器內部,它工作正常,但是在導出為可運行的jar之后,我得到了InvocationTargetException。 我相信它與dll文件有關,但是在這里閱讀了其他解決方案並嘗試實現它們之后,問題仍然沒有解決。 所以我的問題是可以通過代碼或設置來配置Eclipse以正確導出程序嗎?

相關代碼

BTW C:\\ Program Files \\ Tesseract-OCR包含tessdata,gsdll64.dll,liblept170.dll,libtesseract303.dll

Maven依賴項是tess4j,junit,ghost4j

public Bot() {
        System.setProperty("jna.library.path", "C:/Program Files/Tesseract-OCR");
        ocr2 =  new Tesseract();
        ocr2.setDatapath("C:/Program Files/Tesseract-OCR");
        initLists();
        System.out.println(scan(0,0,500,500));
    }
public String scan(int x, int y, int x2, int y2) {
        BufferedImage i = rob.getScreen(x, y, x2, y2);
        i = toBufferedImage(i.getScaledInstance(i.getWidth()*2, i.getHeight() *2, Image.SCALE_SMOOTH));
        try {
            return ocr2.doOCR(i).trim();
        } catch (TesseractException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "";
    }

錯誤

C:\Users\Blue\Desktop>java -jar bot.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: The specified module could not be found.

        at com.sun.jna.Native.open(Native Method)
        at com.sun.jna.Native.open(Native.java:1759)
        at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
        at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
        at com.sun.jna.Library$Handler.<init>(Library.java:147)
        at com.sun.jna.Native.loadLibrary(Native.java:412)
        at com.sun.jna.Native.loadLibrary(Native.java:391)
        at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:78)
        at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:40)
        at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:256)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:237)
        at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:221)
        at debug.Bot.scan(Bot.java:480)
        at debug.Bot.<init>(Bot.java:53)
        at debug.Bot.main(Bot.java:24)
        ... 5 more

C:\Users\Blue\Desktop>pause
Press any key to continue . . .

如果有人遇到類似的問題,我該怎么做,就是將3個.dll文件復制到我的System32文件夾中。 然后我遇到了image.io問題,該站點對此有很多答案。 我的個人解決方案是將jar文件導出為我的代碼,並為庫導出一個單獨的文件夾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM