Google API Vision-java.lang.NoSuchMethodError

Google API Vision-java.lang.NoSuchMethodError,java,api,vision,Java,Api,Vision,我正在尝试运行,但出现以下错误: 线程“main”java.lang.NoSuchMethodError中出现异常:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor 以下是我的项目的特点: 1-POM.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://w

我正在尝试运行,但出现以下错误:

线程“main”java.lang.NoSuchMethodError中出现异常:com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor

以下是我的项目的特点:

1-POM.xml文件

<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>br.com.multiedro</groupId>
    <artifactId>vision</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>API Vision</name>
    <description>Estudando a api vision</description>
    <dependencies>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.22.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-vision</artifactId>
            <version>0.18.0-beta</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
br.com.multiedro
视野
0.0.1-快照
API愿景
Estudando的api愿景
com.google.api-client
谷歌api客户端
1.22.0
com.google.cloud
谷歌云愿景
0.18.0-beta
org.apache.maven.plugins
maven编译器插件
3.6.1
1.8
1.8
2级

package br.com.visio;

// Imports the Google Cloud client library
import com.google.cloud.vision.spi.v1.ImageAnnotatorClient;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Feature.Type;
import com.google.cloud.vision.v1.Image;
import com.google.protobuf.ByteString;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class QuickstartSample {
    public static void main(String... args) throws Exception {
        // Instantiates a client
        ImageAnnotatorClient vision = ImageAnnotatorClient.create();

        // The path to the image file to annotate
        String fileName = "/home/thiago/Imagens/demo-image.jpg";


        // Reads the image file into memory
        Path path = Paths.get(fileName);
        byte[] data = Files.readAllBytes(path);
        ByteString imgBytes = ByteString.copyFrom(data);

        // Builds the image annotation request
        List<AnnotateImageRequest> requests = new ArrayList<>();
        Image img = Image.newBuilder().setContent(imgBytes).build();
        Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();

        AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
        requests.add(request);

        // Performs label detection on the image file
        BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
        List<AnnotateImageResponse> responses = response.getResponsesList();

        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                System.out.printf("Error: %s\n", res.getError().getMessage());
                return;
            }

            for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
                annotation.getAllFields().forEach((k, v) -> System.out.printf("%s : %s\n", k, v.toString()));
            }
        }
    }
}
package br.com.visio;
//导入Google云客户端库
导入com.google.cloud.vision.spi.v1.ImageAnnotatorClient;
导入com.google.cloud.vision.v1.ImageRequest;
导入com.google.cloud.vision.v1.ImageResponse;
导入com.google.cloud.vision.v1.batch注释图像响应;
导入com.google.cloud.vision.v1.EntityAnnotation;
导入com.google.cloud.vision.v1.Feature;
导入com.google.cloud.vision.v1.Feature.Type;
导入com.google.cloud.vision.v1.Image;
导入com.google.protobuf.ByteString;
导入java.nio.file.Files;
导入java.nio.file.Path;
导入java.nio.file.path;
导入java.util.ArrayList;
导入java.util.List;
公共类快速入门示例{
公共静态void main(字符串…参数)引发异常{
//实例化客户机
ImageAnnotatorClient vision=ImageAnnotatorClient.create();
//要注释的图像文件的路径
字符串fileName=“/home/thiago/Imagens/demo image.jpg”;
//将图像文件读入内存
Path Path=Path.get(文件名);
字节[]数据=文件。readAllBytes(路径);
ByteString imgBytes=ByteString.copyFrom(数据);
//生成图像注释请求
列表请求=新建ArrayList();
Image img=Image.newBuilder().setContent(imgBytes.build();
Feature feat=Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
AnnotateImageRequest=AnnotateImageRequest.newBuilder().addFeatures(feat.setImage(img.build));
请求。添加(请求);
//对图像文件执行标签检测
BatchAnnotateImagesResponse=vision.batchAnnotateImages(请求);
List responses=response.getResponsesList();
用于(注释ImageResponse res:responses){
if(res.hasError()){
System.out.printf(“错误:%s\n”,res.getError().getMessage());
返回;
}
对于(EntityAnnotation:res.getLabelAnnotationsList()){
annotation.getAllFields().forEach((k,v)->System.out.printf(“%s:%s\n”,k,v.toString());
}
}
}
}
3-谷歌云SDK 我使用了命令:gcloud auth application default login

有人能帮我吗


谢谢。

我遇到了同样的错误,我尝试过删除依赖项,但不起作用:)这里有同样的问题