gpt4 book ai didi

java - 错误 : No functional channel service provider found. 尝试添加对 grpc-okhttp 或 grpc-netty Artifact 的依赖

转载 作者:行者123 更新时间:2023-12-03 21:01:33 31 4
gpt4 key购买 nike

我正在使用 IntelliJ 在 java 中使用 Cloud Vision API 来检测相机图片中的标签。 API 工作正常,但是当我将 android.graphics 依赖项添加到我的 maven pom.xml 以使用 Bitmap ADT 时,它停止工作并抛出错误:“找不到功能 channel 服务提供者。尝试添加对 grpc 的依赖项-okhttp 或 grpc-netty Artifact ”。我尝试将下面的依赖项添加到我的 pom.xml,但没有任何改变。有人可以告诉我这个错误是什么意思吗?

<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.22.1</version>
</dependency>

这是我的代码:

导入 android.graphics.Bitmap;
public static void main(String... args) throws Exception {
Bitmap bmp;
String description = "";
// Instantiates a client
try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {

// The path to the image file to annotate
String fileName = "c:/stairsPic.png";

// 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
long start = System.currentTimeMillis();
BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
long end = System.currentTimeMillis();
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()) {
description = annotation.getDescription();
break;
}
}
//finding the time difference and converting it into seconds
float sec = (end - start) / 1000F;
System.out.println(sec + " seconds");

System.out.println("The photo description is: " + description);
} catch (Exception e) {
System.out.println(e.toString());
}
}

我在执行“import android.graphics.Bitmap”并声明 Bitmap 变量时收到了上面描述的错误。
我的实际结果是在我的函数签名中获取 Bitmap 并将其发送到云视觉 API 而不会出现此错误。

最佳答案

我有同样的错误,结果是 IntelliJ 错误。
首先,您需要检查您是否有 grpc-netty-shaded IDE 中外部库下的库。就我而言,这是缺失的。我必须手动删除所有库,运行 File -> Invalidate Caches/Restart...然后运行 ​​mvn compile再次。
完成这些步骤后,您应该会看到 grpc-netty-shaded库中的外部库。

关于java - 错误 : No functional channel service provider found. 尝试添加对 grpc-okhttp 或 grpc-netty Artifact 的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57182070/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com