watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
593 stars 532 forks source link

[tone-analyzer] ToneAnalyzer.init(String) NoSuchMethodError #417

Closed abdielou closed 8 years ago

abdielou commented 8 years ago

I'm trying to run the Tone Analyzer Example but it won't initialize. Below is the error I'm getting.

JDK version - 1.8 java-sdk version - 3.0.1 & 3.2.0

Exception in thread "main" java.lang.NoSuchMethodError: com.ibm.watson.developer_cloud.service.WatsonService.<init>(Ljava/lang/String;)V
    at com.ibm.watson.developer_cloud.tone_analyzer.v3.ToneAnalyzer.<init>(ToneAnalyzer.java:61)
    at ToneAnalyzerExample.main(ToneAnalyzerExample.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
germanattanasio commented 8 years ago

I tried the example in a new Android project and it worked.

Make sure you are using 3.2.0 which is the latest version at this point.

String text = "I know the times are difficult! Our sales have been "
    + "disappointing for the past three-quarters for our data analytics "
    + "product suite. We have a competitive data analytics product "
    + "suite in the industry. But we need to do our job selling it! "
    + "We need to acknowledge and fix our sales challenges. "
    + "We can’t blame the economy for our lack of execution! "
    + "We are missing critical sales opportunities. "
    + "Our product is in no way inferior to the competitor products. "
    + "Our clients are hungry for analytical tools to improve their "
    + "business outcomes. The economy has nothing to do with it.";

ToneAnalyzer toneAnalyzer = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_05_19);
toneAnalyzer.setUsernameAndPassword("USERNAME", "PASSWORD");
toneAnalyzer.getTone(text, null).enqueue(new ServiceCallback<ToneAnalysis>() {
    @Override
    public void onFailure(Exception e) {}

    @Override
    public void onResponse(final ToneAnalysis tone) {
        // Run view-related code back on the main thread
        MainActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                System.out.print(tone);
            }
        });
    };
});