NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45247193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
提问by quarks
What Google Maven dependency could fix this error:
哪些 Google Maven 依赖项可以修复此错误:
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V
at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:487)
at com.google.cloud.storage.BlobReadChannel.call(BlobReadChannel.java:127)
at com.google.cloud.storage.BlobReadChannel.call(BlobReadChannel.java:124)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:94)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:54)
at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:124)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
at java.io.InputStream.read(InputStream.java:101)
Code:
代码:
Blob blob = storage.get(blobId);
if(blob.exists()) {
return true;
}
采纳答案by Laurent Perez
Your Google guava version is either too old (< 20.0) or mismatched (multiple jars versions). Make sure you don't have several versions in your dependency tree.
您的 Google 番石榴版本太旧 (< 20.0) 或不匹配(多个 jars 版本)。确保您的依赖树中没有多个版本。
Use
用
mvn dependency:tree | less
to look for the guava versions.
寻找番石榴版本。
回答by Avinash Pande
Please add following dependencies to your project's POM:
请将以下依赖项添加到您项目的 POM 中:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.8</version>
</dependency>
回答by Adam Hurwitz
I had the same issue in my Java/Kotlin application. When the app was ran via IntelliJ there were no issues. However, when the .Jarwas ran the error message above was thrown.
我在 Java/Kotlin 应用程序中遇到了同样的问题。当应用程序通过 IntelliJ 运行时,没有任何问题。但是,当.Jar运行时,上面的错误消息被抛出。
I could not find a direct action item to take with the Guava issue defined by @Laurent Perez above so I did the following which resolved the issue with my .Jarfile running:
对于上面@Laurent Perez 定义的 Guava 问题,我找不到要采取的直接操作项,因此我执行了以下操作,解决了运行.Jar文件的问题:
- Removed .JarIntelliJ configurations and file from IntelliJ. Then re-added the .Jarfollowing Step 3from this deploy guide.
- 从 IntelliJ 中删除了.JarIntelliJ 配置和文件。然后按照本部署指南的第 3 步重新添加.Jar。
Other actions to try if the above does not work:
如果上述方法不起作用,请尝试其他操作:
- Rebuild project.
- Invalidate IntelliJ cache and restart.
- Restart computer.
- 重建项目。
- 使 IntelliJ 缓存无效并重新启动。
- 重新启动计算机。
回答by Gapmeister66
Try inserting a dependency containing a newer version of guava at the top of your dependencies in your pom.xml containing your project.
尝试在包含项目的 pom.xml 中的依赖项顶部插入包含较新版本番石榴的依赖项。
E.g.
例如
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.1.1-jre</version>
</dependency>
回答by sabbir
In my case, I happened to include both
就我而言,我碰巧包括了两者
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
and
和
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>
As it turns out, I cannot use both of these libraries. Removing google-collections fixed the issue for me.
事实证明,我不能同时使用这两个库。删除 google-collections 为我解决了这个问题。
回答by rolyn
For anybody encountering anything like this, i had the following pom:
对于遇到这样的事情的任何人,我有以下 pom:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
</dependency>
And commenting out the maven-shade plugin fixed it for me...
并注释掉 maven-shade 插件为我修复了它......