本文介绍了JUnit抛出java.lang.NoSuchMethodError对于com.google.common.collect.Iterables.tryFind的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Guava v13.0但是当我使用包含tryFind的代码运行JUnit测试时,我收到以下消息:

I am using Google Guava v13.0 but when I run a JUnit test with code containing tryFind, I get this message:

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。

This only seems to happen with JUnit tests as when the production code runs there are no problems. I am using Intellij IDEA v11.1.3 and can navigate into the guava JAR file to find tryFind in the com.google.common.collect.Iterable.class.

我'我看过类似的帖子,但我不确定这与JUnit有什么关系。关于我的问题可能是什么想法?

I've seen similar posts, but I'm not sure how this relates to JUnit. Any ideas on what my issue might be?

推荐答案

这种错误通常是由于旧版本的番石榴造成的(或者除了您尝试使用的较新版本之外,还会在类路径上添加google-collections。尝试在运行测试时检查类路径上的内容。

This sort of error is usually caused by having an older version of Guava (or even google-collections) on the classpath in addition to the newer version you're trying to use. Try to check what's on the classpath when running your test.

这篇关于JUnit抛出java.lang.NoSuchMethodError对于com.google.common.collect.Iterables.tryFind的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 13:43