I'm working on alchemy API. The Reference link used Alchemy Ref .
My Android code
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try
{
AlchemyLanguage service = new AlchemyLanguage();
service.setApiKey("xxx - My API Key");
Map<String,Object> param = new HashMap<String, Object>();
param.put(AlchemyLanguage.TEXT, TextValue);
DocumentSentiment sentiment = service.getSentiment(param).execute();
SentimentValue = sentiment.getText();
System.out.println(sentiment);
SentimentType = sentiment.getSentiment().getType().name();
}
catch (Exception ex)
{
Log.d("Exception : " , ex.toString());
}
}
});
thread.start();
Toast.makeText(MainActivity.this, SentimentType+" ", Toast.LENGTH_SHORT).show();
The program terminates during the initialization of the class
AlchemyLanguage service = new AlchemyLanguage();
Log :
E/dalvikvm: Could not find class 'javax.naming.InitialContext', referenced from method com.ibm.watson.developer_cloud.util.CredentialUtils.getKeyUsingJNDI
W/dalvikvm: VFY: unable to resolve new-instance 2848 (Ljavax/naming/InitialContext;) in Lcom/ibm/watson/developer_cloud/util/CredentialUtils;
D/dalvikvm: VFY: replacing opcode 0x22 at 0x0007
W/dalvikvm: VFY: unable to resolve exception class 2849 (Ljavax/naming/NamingException;)
W/dalvikvm: VFY: unable to find exception handler at addr 0x2e
W/dalvikvm: VFY: rejected Lcom/ibm/watson/developer_cloud/util/CredentialUtils;.getKeyUsingJNDI (Ljava/lang/String;)Ljava/lang/String;
W/dalvikvm: VFY: rejecting opcode 0x0d at 0x002e
W/dalvikvm: VFY: rejected Lcom/ibm/watson/developer_cloud/util/CredentialUtils;.getKeyUsingJNDI (Ljava/lang/String;)Ljava/lang/String;
W/dalvikvm: Verifier rejected class Lcom/ibm/watson/developer_cloud/util/CredentialUtils;
W/dalvikvm: threadid=12: thread exiting with uncaught exception (group=0x40d9e468)
E/AndroidRuntime: FATAL EXCEPTION: Thread-754
java.lang.VerifyError: com/ibm/watson/developer_cloud/util/CredentialUtils
at com.ibm.watson.developer_cloud.service.WatsonService.<init>(WatsonService.java:102)
at com.ibm.watson.developer_cloud.service.AlchemyService.<init>(AlchemyService.java:55)
at com.ibm.watson.developer_cloud.alchemy.v1.AlchemyLanguage.<init>(AlchemyLanguage.java:54)
at com.numarga.alchemyinbuildtest.MainActivity$1$1.run(MainActivity.java:53)
at java.lang.Thread.run(Thread.java:856)
I/Process: Sending signal. PID: 23131 SIG: 9
Application terminated.
This was a bug in the Java SDK. Make sure you use a version > 3.5.0 in gradle, use something like 3.7.1
'com.ibm.watson.developer_cloud:alchemy:3.7.1'
Then call AlchemyLanguage sentiment analysis:
AlchemyLanguage service = new AlchemyLanguage();
service.setApiKey("xxx - My API Key");
Map<String,Object> param = new HashMap<String, Object>();
param.put(AlchemyLanguage.TEXT, TextValue);
DocumentSentiment sentiment = service.getSentiment(param).execute();
System.out.println(sentiment);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.