英文:
"main" java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, char, java.lang.Object)'
问题
我尝试了不同版本的可用的JAR包,但在我的IntelliJ工作空间中仍然找不到Preconditions
类,我一直在遇到这个错误。
每次运行代码时,我都会得到这个运行时异常,我不确定为什么会调用这个方法。这是我第一次尝试使用gRPC和Protocol Buffers,但我不确定如何处理下面的错误。
依赖关系如下:
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.29.0</version>
</dependency>
<!-- 其他依赖项 -->
</dependencies>
我的mvn dependency:tree
输出如下:
[INFO] +- io.grpc:grpc-all:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-api:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-auth:jar:1.29.0:compile
[INFO] | | \- com.google.auth:google-auth-library-credentials:jar:0.20.0:compile
[INFO] | +- io.grpc:grpc-context:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-core:jar:1.29.0:compile
[INFO] | | +- com.google.code.gson:gson:jar:2.8.6:compile
[INFO] | | +- com.google.android:annotations:jar:4.1.1.4:compile
[INFO] | | \- io.perfmark:perfmark-api:jar:0.19.0:compile
[INFO] | +- io.grpc:grpc-grpclb:jar:1.29.0:compile
[INFO] | | +- com.google.protobuf:protobuf-java:jar:3.11.0:compile
[INFO] | | \- com.google.protobuf:protobuf-java-util:jar:3.11.0:compile
[INFO] | +- io.grpc:grpc-netty:jar:1.29.0:compile
[INFO] | | +- io.netty:netty-codec-http2:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-common:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-transport:jar:4.1.48.Final:compile
[INFO] | | | | \- io.netty:netty-resolver:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-codec:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-handler:jar:4.1.48.Final:compile
[INFO] | | | \- io.netty:netty-codec-http:jar:4.1.48.Final:compile
[INFO] | | \- io.netty:netty-handler-proxy:jar:4.1.48.Final:compile
[INFO] | | \- io.netty:netty-codec-socks:jar:4.1.48.Final:compile
[INFO] | +- io.grpc:grpc-okhttp:jar:1.29.0:compile
[INFO] | | +- com.squareup.okio:okio:jar:1.13.0:compile
[INFO] | | \- com.squareup.okhttp:okhttp:jar:2.7.4:compile
[INFO] | +- io.grpc:grpc-protobuf:jar:1.29.0:compile
[INFO] | | +- com.google.api.grpc:proto-google-common-protos:jar:1.17.0:compile
[INFO] | | \- io.grpc:grpc-protobuf-lite:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-services:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-stub:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-testing:jar:1.29.0:compile
[INFO] | | \- io.opencensus:opencensus-api:jar:0.24.0:compile
[INFO] | \- io.grpc:grpc-xds:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-alts:jar:1.29.0:compile
[INFO] | | +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] | | +- org.conscrypt:conscrypt-openjdk-uber:jar:2.2.1:compile
[INFO] | | \- com.google.auth:google-auth-library-oauth2-http:jar:0.20.0:compile
[INFO] | | +- com.google.http-client:google-http-client:jar:1.34.0:compile
[INFO] | | | +- org.apache.httpcomponents:httpclient:jar:4.5.10:compile
[INFO] | | | | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | | | | \- commons-codec:commons-codec:jar:1.11:compile
[INFO] | | | \- io.opencensus:opencensus-contrib-http-util:jar:0.24.0:compile
[INFO] | | \- com.google.http-client:google-http-client-jackson2:jar:1.34.0:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.10.1:compile
[INFO] | +- io.opencensus:opencensus-proto:jar:0.2.0:compile
[INFO] | \- io.grpc:grpc-netty-shaded:jar:1.29.0:compile
[INFO] +- com.google.auto.value:auto-value-annotations:jar:1.6.2:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- commons-cli:commons-cli:jar:1.4:compile
[INFO]
<details>
<summary>英文:</summary>
I am getting this error, even after trying different versions of jars available and unable to find the `Preconditions` class in my intelliJ workspace.
Not sure why this method is getting called. I'm getting this runtime exception every time i run the code.
I am trying grpc and protobuffers for the first time but I'm not sure what to do about the below error.
> ```
> "main" java.lang.NoSuchMethodError:
> 'void com.google.common.base.Preconditions.checkArgument(
> boolean, java.lang.String, char, java.lang.Object)'
> ```
My **dependencies** look like this:
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.29.0</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.8</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.49.Final</version>
</dependency>
</dependencies>
And my **mvn dependency:tree o/p is below**.
[INFO] +- io.grpc:grpc-all:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-api:jar:1.29.0:compile (version selected from constraint [1.29.0,1.29.0])
[INFO] | +- io.grpc:grpc-auth:jar:1.29.0:compile
[INFO] | | \- com.google.auth:google-auth-library-credentials:jar:0.20.0:compile
[INFO] | +- io.grpc:grpc-context:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-core:jar:1.29.0:compile (version selected from constraint [1.29.0,1.29.0])
[INFO] | | +- com.google.code.gson:gson:jar:2.8.6:compile
[INFO] | | +- com.google.android:annotations:jar:4.1.1.4:compile
[INFO] | | \- io.perfmark:perfmark-api:jar:0.19.0:compile
[INFO] | +- io.grpc:grpc-grpclb:jar:1.29.0:compile
[INFO] | | +- com.google.protobuf:protobuf-java:jar:3.11.0:compile
[INFO] | | \- com.google.protobuf:protobuf-java-util:jar:3.11.0:compile
[INFO] | +- io.grpc:grpc-netty:jar:1.29.0:compile
[INFO] | | +- io.netty:netty-codec-http2:jar:4.1.48.Final:compile (version selected from constraint [4.1.48.Final,4.1.48.Final])
[INFO] | | | +- io.netty:netty-common:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-buffer:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-transport:jar:4.1.48.Final:compile
[INFO] | | | | \- io.netty:netty-resolver:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-codec:jar:4.1.48.Final:compile
[INFO] | | | +- io.netty:netty-handler:jar:4.1.48.Final:compile
[INFO] | | | \- io.netty:netty-codec-http:jar:4.1.48.Final:compile
[INFO] | | \- io.netty:netty-handler-proxy:jar:4.1.48.Final:compile
[INFO] | | \- io.netty:netty-codec-socks:jar:4.1.48.Final:compile
[INFO] | +- io.grpc:grpc-okhttp:jar:1.29.0:compile
[INFO] | | +- com.squareup.okio:okio:jar:1.13.0:compile
[INFO] | | \- com.squareup.okhttp:okhttp:jar:2.7.4:compile
[INFO] | +- io.grpc:grpc-protobuf:jar:1.29.0:compile
[INFO] | | +- com.google.api.grpc:proto-google-common-protos:jar:1.17.0:compile
[INFO] | | \- io.grpc:grpc-protobuf-lite:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-services:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-stub:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-testing:jar:1.29.0:compile
[INFO] | | \- io.opencensus:opencensus-api:jar:0.24.0:compile
[INFO] | \- io.grpc:grpc-xds:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-alts:jar:1.29.0:compile
[INFO] | | +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] | | +- org.conscrypt:conscrypt-openjdk-uber:jar:2.2.1:compile
[INFO] | | \- com.google.auth:google-auth-library-oauth2-http:jar:0.20.0:compile
[INFO] | | +- com.google.http-client:google-http-client:jar:1.34.0:compile
[INFO] | | | +- org.apache.httpcomponents:httpclient:jar:4.5.10:compile
[INFO] | | | | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | | | | \- commons-codec:commons-codec:jar:1.11:compile
[INFO] | | | \- io.opencensus:opencensus-contrib-http-util:jar:0.24.0:compile
[INFO] | | \- com.google.http-client:google-http-client-jackson2:jar:1.34.0:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.10.1:compile
[INFO] | +- io.opencensus:opencensus-proto:jar:0.2.0:compile
[INFO] | \- io.grpc:grpc-netty-shaded:jar:1.29.0:compile (version selected from constraint [1.29.0,1.29.0])
[INFO] +- com.google.auto.value:auto-value-annotations:jar:1.6.2:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- commons-cli:commons-cli:jar:1.4:compile
[INFO] +- com.google.guava:guava:jar:22.0:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] | +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.4.8:compile
[INFO] \- io.netty:netty-all:jar:4.1.49.Final:compile
I have checked the existing posts as well on this issue but none seems to be working for me. I believe there might be some issue with the versions but all the versions seem to be giving this error only.
</details>
# 答案1
**得分**: 4
问题与第三方库有关:
"main" java.lang.NoSuchMethodError:
'void com.google.common.base.Preconditions.checkArgument(
boolean, java.lang.String, char, java.lang.Object)'
让我们尝试更新 guava
```xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
英文:
Problem with a 3rd Party Library:
"main" java.lang.NoSuchMethodError:
'void com.google.common.base.Preconditions.checkArgument(
boolean, java.lang.String, char, java.lang.Object)'
Let's try to update guava
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论