"main" java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, char, java.lang.Object)'

huangapple go评论65阅读模式
英文:

"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&#39;m getting this runtime exception every time i run the code.  
I am trying grpc and protobuffers for the first time but I&#39;m not sure what to do about the below error.  

&gt; ```
&gt; &quot;main&quot; java.lang.NoSuchMethodError: 
&gt; &#39;void com.google.common.base.Preconditions.checkArgument(  
&gt;          boolean, java.lang.String, char, java.lang.Object)&#39;
&gt; ```
    
My **dependencies** look like this:
    
     &lt;dependencies&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;io.grpc&lt;/groupId&gt;
                &lt;artifactId&gt;grpc-all&lt;/artifactId&gt;
                &lt;version&gt;1.29.0&lt;/version&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;com.google.auto.value&lt;/groupId&gt;
                &lt;artifactId&gt;auto-value-annotations&lt;/artifactId&gt;
                &lt;version&gt;1.6.2&lt;/version&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;junit&lt;/groupId&gt;
                &lt;artifactId&gt;junit&lt;/artifactId&gt;
                &lt;version&gt;4.12&lt;/version&gt;
                &lt;scope&gt;test&lt;/scope&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;com.google.inject&lt;/groupId&gt;
                &lt;artifactId&gt;guice&lt;/artifactId&gt;
                &lt;version&gt;4.2.2&lt;/version&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;commons-cli&lt;/groupId&gt;
                &lt;artifactId&gt;commons-cli&lt;/artifactId&gt;
                &lt;version&gt;1.4&lt;/version&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
                &lt;artifactId&gt;guava&lt;/artifactId&gt;
                &lt;version&gt;20.0&lt;/version&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
                &lt;artifactId&gt;httpcore&lt;/artifactId&gt;
                &lt;version&gt;4.4.8&lt;/version&gt;
            &lt;/dependency&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;io.netty&lt;/groupId&gt;
                &lt;artifactId&gt;netty-all&lt;/artifactId&gt;
                &lt;version&gt;4.1.49.Final&lt;/version&gt;
            &lt;/dependency&gt;
        &lt;/dependencies&gt;
    
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:

&quot;main&quot; java.lang.NoSuchMethodError: 
&#39;void com.google.common.base.Preconditions.checkArgument(  
boolean, java.lang.String, char, java.lang.Object)&#39;

Let's try to update guava

    &lt;dependency&gt;
&lt;groupId&gt;com.google.guava&lt;/groupId&gt;
&lt;artifactId&gt;guava&lt;/artifactId&gt;
&lt;version&gt;21.0&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年5月5日 19:29:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/61612081.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定