简体   繁体   English

JUnit抛出java.lang.NoSuchMethodError对于com.google.common.collect.Iterables.tryFind

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

I am using Google Guava v13.0 but when I run a JUnit test with code containing tryFind, I get this message: 我正在使用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;

This only seems to happen with JUnit tests as when the production code runs there are no problems. 这似乎只发生在JUnit测试中,因为生产代码运行时没有问题。 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. 我正在使用Intellij IDEA v11.1.3并可以导航到guava JAR文件以在com.google.common.collect.Iterable.class中找到tryFind。

I've seen similar posts, but I'm not sure how this relates to JUnit. 我见过类似的帖子,但我不确定这与JUnit有什么关系。 Any ideas on what my issue might be? 关于我的问题可能是什么想法?

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. 除了您尝试使用的较新版本之外,这种错误通常是由类路径上的旧版Guava(甚至是google-collections)引起的。 Try to check what's on the classpath when running your test. 在运行测试时尝试检查类路径上的内容。

Go with Colin's answer, here's a nice way to detect where the stuff is loaded: 与Colin的答案一起,这是检测内容加载位置的好方法:

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

This should print out the path to the guava (or gc) version you are using. 这应该打印出您正在使用的番石榴(或gc)版本的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google通讯录-java.lang.NoSuchMethodError:com.google.common.collect.ImmutableSet.of([Ljava / lang / Object;)Lcom / google / common / collect / ImmutableSet; - Google Contacts - java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet; java.lang.NoSuchMethodError:带有Selenium和Java的com.google.common.collect.ImmutableSet.of([Ljava / lang / Object;) - java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;) with Selenium and Java java.lang.NoSuchMethodError:com.google.common.collect.Sets.newConcurrentHashSet - java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet 卡夫卡连接 java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator; - Kafka Connect java.lang.NoSuchMethodError: com.google.common.collect.Sets$SetView.iterator()Lcom/google/common/collect/UnmodifiableIterator; 泽西岛启动问题:java.lang.NoSuchMethodError:com.google.common.collect.Sets.newIdentityHashSet() - Jersey Startup Issue : java.lang.NoSuchMethodError: com.google.common.collect.Sets.newIdentityHashSet() java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.toImmutableSet() 即使使用“com.google.guava:guava:24.0-android” - java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.toImmutableSet() even with 'com.google.guava:guava:24.0-android' java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using Selenium Java - java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using Selenium Java java.lang.NoSuchMethodError:com.google.common.base.Preconditions - java.lang.NoSuchMethodError: com.google.common.base.Preconditions java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' 使用 ChromeDriver 和 Selenium - java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableList.toImmutableList()' using ChromeDriver and Selenium java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap 尝试使用 Chromedriver 和 Maven 执行测试时出错 - java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap error when trying to execute tests using Chromedriver and Maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM