简体   繁体   中英

NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V

I'm trying to create an API which, when triggered, sends a request to Dialogflow. To do that, I'm using the Java SDK, as found here .

The problematic code snippet is copy-pasted from here , to the bottom of the page.

try (SessionsClient sessionsClient = SessionsClient.create()) {
    SessionName session = SessionName.of(genericProjectId, genericSessionId);
    QueryInput queryInput = QueryInput.newBuilder().build();
    DetectIntentResponse response = sessionsClient.detectIntent(session, 
    queryInput);
}

When I run "SessionsClient.create()", the error

javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V

is thrown at runtime. After research, it looks like this has something to do with different versions of the libraries being included, mainly protobuf and guava ; however, I trimmed my POM as much as possible, and it doesn't go away.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>MYPROJECTNAME</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-dialogflow</artifactId>
            <version>0.71.0-alpha</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>MYPROJECTNAME</finalName>
        <plugins>
        </plugins>
    </build>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <projectId>MYPROJECTID</projectId>
    </properties>
</project>

Running mvn depenceny:tree doesn't show any problems, and by opening the WAR archive created I can't see any duplicate library. Tried compiling both with NetBeans and by command line, the problem still persists. The application is running on Windows, using Java 8 and Payara as server. What am I doing wrong?

Thanks for any help

I had the same problem and added this to my pom.xml and this fixed the error:

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.6-jre</version>
        </dependency>

After raising an issue on Google Cloud repository, it looks like this was indeed a problem with Guava , so it's a bug on their side. I'm still unsure about how could this pass unnoticed, since somehow their quickstart guide must have worked at some point, but here it is. Thanks to those who bothered upvoting the question.

Besides adding the dependency for Guava from here:

https://mvnrepository.com/artifact/com.google.guava/guava

make sure it is above others in the pom.xml file, that mattered in my case. I assume if other Guava versions are loaded as dependencies first, those are used. I did not find that in the output of :

mvn dependency:tree 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V Google Cloud KMS java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V Error :: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V Error:Cause: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;J)V NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;) java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V with IE and Selenium through Java Maven - NoSuchMethodError: void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object) java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object) “main” java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, char, java.lang.Object)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM