Cloud Vision API Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument

huangapple 未分类评论43阅读模式
英文:

Cloud Vision API Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument

问题

我按照 https://cloud.google.com/vision/docs/ocr 中的所有步骤进行操作,但在执行代码时出现以下异常。

完整的堆栈跟踪:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
	at io.grpc.Metadata$Key.validateName(Metadata.java:742)
	at io.grpc.Metadata$Key.<init>(Metadata.java:750)
	at io.grpc.Metadata$Key.<init>(Metadata.java:668)
	at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:959)
	at io.grpc.Metadata$AsciiKey.<init>(Metadata.java:954)
	at io.grpc.Metadata$Key.of(Metadata.java:705)
	at io.grpc.Metadata$Key.of(Metadata.java:701)
	at com.google.api.gax.grpc.GrpcHeaderInterceptor.<init>(GrpcHeaderInterceptor.java:60)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:228)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access$1500(InstantiatingGrpcChannelProvider.java:71)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.createSingleChannel(InstantiatingGrpcChannelProvider.java:202)
	at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:209)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:192)
	at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:155)
	at com.google.cloud.vision.v1.stub.GrpcImageAnnotatorStub.create(GrpcImageAnnotatorStub.java:117)
	at com.google.cloud.vision.v1.stub.ImageAnnotatorStubSettings.createStub(ImageAnnotatorStubSettings.java:156)
	at com.google.cloud.vision.v1.ImageAnnotatorClient.<init>(ImageAnnotatorClient.java:136)
	at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:117)
	at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:108)

我尝试使用不同于 Google Cloud Platform Libraries(版本为 28.2 和 4.4.12)中已使用的 Guava 版本(22.0 和 23.6)以及 HttpCore 版本(5.0 和 4.4.8),但没有成功。

我正在使用 Eclipse,并按照 https://cloud.google.com/eclipse/docs/libraries 中的步骤进行操作。

英文:

I followed all the steps in https://cloud.google.com/vision/docs/ocr and when executing the code I get the following Exception.

Full Stacktrace:

Exception in thread &quot;main&quot; java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V
	at io.grpc.Metadata$Key.validateName(Metadata.java:742)
	at io.grpc.Metadata$Key.&lt;init&gt;(Metadata.java:750)
	at io.grpc.Metadata$Key.&lt;init&gt;(Metadata.java:668)
	at io.grpc.Metadata$AsciiKey.&lt;init&gt;(Metadata.java:959)
	at io.grpc.Metadata$AsciiKey.&lt;init&gt;(Metadata.java:954)
	at io.grpc.Metadata$Key.of(Metadata.java:705)
	at io.grpc.Metadata$Key.of(Metadata.java:701)
	at com.google.api.gax.grpc.GrpcHeaderInterceptor.&lt;init&gt;(GrpcHeaderInterceptor.java:60)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:228)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access$1500(InstantiatingGrpcChannelProvider.java:71)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.createSingleChannel(InstantiatingGrpcChannelProvider.java:202)
	at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:209)
	at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:192)
	at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:155)
	at com.google.cloud.vision.v1.stub.GrpcImageAnnotatorStub.create(GrpcImageAnnotatorStub.java:117)
	at com.google.cloud.vision.v1.stub.ImageAnnotatorStubSettings.createStub(ImageAnnotatorStubSettings.java:156)
	at com.google.cloud.vision.v1.ImageAnnotatorClient.&lt;init&gt;(ImageAnnotatorClient.java:136)
	at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:117)
	at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:108)

I tried using different Guava (22.0 and 23.6) and HttpCore (5.0 and 4.4.8) versions than the ones already being used on the Google Cloud Platform Libraries (28.2 and 4.4.12) but got no luck.

I'm using Eclipse and used the Eclipse and followed these steps: https://cloud.google.com/eclipse/docs/libraries

答案1

得分: 0

正如您所指出的,这种类型的错误通常表明版本不匹配。您尚未说明您是使用Maven还是Cloud Tools for Eclipse本地项目。我建议您使用Maven设置,以便您可以利用Cloud Libraries BOM。这应该可以消除这些版本不匹配问题。

英文:

As you noted, this kind of errors typically indicate version mismatches. You haven't said whether you're using Maven or the Cloud Tools for Eclipse native project. I'd recommend you use a Maven setup so that you can take advantage of the Cloud Libraries BOM. That should eliminate these version mismatches.

答案2

得分: 0

那个堆栈跟踪表明你的类路径包含了一个旧版本的Guava,或者OCR客户端,或者两者都有。如果没有一个完整的项目供我检查,我无法确切地说出你是如何获取到那个旧版本的 - 这取决于你如何配置项目 - 但这绝对是正在发生的事情。

英文:

That stacktrace indicates your classpath includes an old version of Guava, or the OCR client, or both. Without a complete project to inspect, I can't say exactly how you're getting that old version--it depends on how you've configured the project--but that is definitely what's happening.

答案3

得分: 0

好的,我从GitHub上的https://github.com/googleapis/java-vision 项目中克隆了整个Java Vision项目。然而,由于存在路径错误,我仍然不得不添加一些额外的JAR包。

英文:

Ok, I made this run cloning the whole java vision project from GitHub: https://github.com/googleapis/java-vision.

However I still had to add some extra jars since path errors existed.

huangapple
  • 本文由 发表于 2020年4月4日 08:13:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61022224.html
匿名

发表评论

匿名网友

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

确定