0
votes

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 "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)

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

3
Would you share your pom.xml? I'm interested in dependency and dependencyManagement section. - suztomo
here is the pom.xml: jsfiddle.net/2m438wfd - Nicolas Guffanti
I was able to make this run downloading the whole project from GitHub, see last answer. - Nicolas Guffanti
I don't see you're using the GCP Libraries BOM. Document: github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/… . Basically, with the BOM, you don't need to set individual versions of the libraries. - suztomo
Yes, I added those lines to the pom.xml file, but I still was unable to run it correctly. I really don't know what was wrong, and was able to fix it cloning the whole vision project. - Nicolas Guffanti

3 Answers

0
votes

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.

0
votes

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.

0
votes

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.