【发布时间】:2014-02-17 23:28:53
【问题描述】:
我使用的是 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 有何关系。关于我的问题的任何想法?
【问题讨论】:
-
你用maven吗?也许罐子不在范围内?
-
这似乎更可能是类路径或构建框架问题,而不是 Guava 问题。
-
我们不使用 Maven。所有库都是手动添加到项目中的。
-
@atamanroman; AFAIK,丢失的 jar 永远不会导致
NoSuchMethodError,因为你首先得到NoSuchClassException。 -
@maaartinus true,好像包含了不同版本的番石榴
标签: java junit guava nosuchmethoderror