2014-02-14 216 views
0

正在使用僑光罐子從Java調用代碼的Excel工作表的宏..越來越java.lang.NoSuchMethodError

final ActiveXComponent excel = new ActiveXComponent("Excel.Application"); 
final Dispatch workbooks = excel.getProperty("Workbooks") .toDispatch(); 
final Dispatch workBook = Dispatch.call(workbooks, "Open", file.getAbsolutePath()).toDispatch(); 

com.jacob.com.Variant f = new com.jacob.com.Variant(true); 
Dispatch.call(workBook, "Close", f); 

也正在使用Maven來添加所有的jar依賴。但後來我意識到,我需要添加.dll文件,然後我手動添加雅各JAR和機庫給了dll文件,但現在我得到

Exception in thread "main" java.lang.NoSuchMethodError: com.jacob.com.Dispatch.call(Lcom/jacob/com/Dispatch;Ljava/lang/String;Ljava/lang/Object;)Lcom/jacob/com/Variant; 
     at com.common.getData.callMacro(getData.java:650) 
     at com.testcases.PathAndAction.testScreen(PathAndAction.java:874) 
     at com.testcases.MainTestClass.testScreen(MainTestClass.java:54) 
     at com.testcases.MainTestClass.main(MainTestClass.java:15) 

回答

3

這可能意味着,在運行時,罐子的版本, '與com.jacob.com.Dispatch使用不同的是com.common.getData被編譯。它告訴你類com.jacob.com.Dispatch確實存在,但它沒有名爲call的方法,它以Dispatch, String, Object作爲參數。

你也許用一個罐子編譯,但用另一個罐子運行?

+0

是的,還有其他一些可能導致異常的情況,但通常意味着用於編譯的jar和用於運行的jar之間存在版本不匹配。 –

+0

其他情況會是什麼? –

+0

我想記住 - 它們被引入ca 1.2或1.3,並且我認爲這是當接口的繼承細節發生變化時,並且變得可能讓一個類實現一個沒有所有方法的接口。或者是這個效果。但是,當時孫相當混亂,所以我的記憶很模糊。 –