I am trying to use google natural language processing api. I add libraries using Maven and add the GOOGLE_APPLICATION_CREDENTIALSas environment variable which is having the path to a JSON file that contains my service account key.

It is giving me an error; Could not find TLS ALPN provider; no working netty-tcnative, Conscrypt, or Jetty NPN/ALPN available

try (LanguageServiceClient language = LanguageServiceClient.create()) {

            // The text to analyze
            String text = "Hello, world!";
            Document doc = Document.newBuilder()
                    .setContent(text).setType(Type.PLAIN_TEXT).build();

            // Detects the sentiment of the text
            Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();

            System.out.printf("Text: %s%n", text);
            System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude());
        }catch(Exception e){
            System.out.println("Gevindu Error "+ e.getMessage());
        }
1

There are 1 best solutions below

0
On

There isn't much data to be sure about correct answer, but in my case error was because I was using java version 1.8, I change compile properties to 1.9 and error gone:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
            <source>1.9</source>
            <target>1.9</target>
            <optimize>true</optimize>
            <debug>true</debug>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>