簡體   English   中英

JUnit拋出java.lang.NoSuchMethodError對於com.google.common.collect.Iterables.tryFind

[英]JUnit throws java.lang.NoSuchMethodError For com.google.common.collect.Iterables.tryFind

我正在使用Google Guava v13.0但是當我使用包含tryFind的代碼運行JUnit測試時,我收到以下消息:

java.lang.NoSuchMethodError: com.google.common.collect.Iterables.tryFind(Ljava/lang/Iterable;Lcom/google/common/base/Predicate;)Lcom/google/common/base/Optional;

這似乎只發生在JUnit測試中,因為生產代碼運行時沒有問題。 我正在使用Intellij IDEA v11.1.3並可以導航到guava JAR文件以在com.google.common.collect.Iterable.class中找到tryFind。

我見過類似的帖子,但我不確定這與JUnit有什么關系。 關於我的問題可能是什么想法?

除了您嘗試使用的較新版本之外,這種錯誤通常是由類路徑上的舊版Guava(甚至是google-collections)引起的。 在運行測試時嘗試檢查類路徑上的內容。

與Colin的答案一起,這是檢測內容加載位置的好方法:

System.out.println(
    Iterables.class.getProtectionDomain().getCodeSource().getLocation()
);

這應該打印出您正在使用的番石榴(或gc)版本的路徑。

暫無
暫無

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

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