Javax content not accessible

拜拜、爱过 提交于 2019-12-11 06:47:26

问题


I have a runtime error when i try to run my android application, due to the importation of this package that allows me to use Watson Services.

'com.ibm.watson.developer_cloud:java-sdk:2.9.0'

In fact, when I use something related to this package, the error that appears is:

E/dalvikvm: Could not find class 'javax.naming.InitialContext', referenced from method com.ibm.watson.developer_cloud.util.CredentialUtils.getKeyUsingJNDI

and the corresponding stacktrace is:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: semantic.myapplication, PID: 29120
java.lang.VerifyError: com/ibm/watson/developer_cloud/util/CredentialUtils
at….

I’ve looked for the real problem of this error and I’ve found that in the file “CredentialUtils.java” where the error appears, these three importations are not recognized (Cannot resolve symbols):

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

I use Android Studio and the latest version of jdk (1.8.0.77). These java files exist, I can see them but for some reason are not accessible: the importation of every file in javax.naming (and also other folders) is not possible.

How can I solve this problem? I’ve tried to import a .jar file including the javax.naming classes, but doesn’t work. Is there a way to make visible that classes?

Any help would be appreciated. Thanks!


回答1:


I think you are using a version older than 2.7.1. I'm unable to reproduce your problem and I tried with different configurations including yours. Make sure you clean your workspace and get the latest version of the library. In your build.gradle you should have:

compile 'com.ibm.watson.developer_cloud:java-sdk:2.9.0'

Here is the commit that fixed your issue. The fix was released in the 2.7.1 version.

This is what I did and that worked for me:

Steps to use the Watson APIs in Android you should:

  1. Download and install Android Studio
  2. Open Android Studio
  3. File > New > New Project.
  4. Pick a name and click next, next, next and Finish
  5. In <project-name>/app/build.gradle add:

    compile 'com.ibm.watson.developer_cloud:java-sdk:2.9.0'  
    
  6. In MainActiviy.java at the end of onCreate(...) add:

    Thread thread = new Thread(new Runnable(){
      @Override
      public void run() {
        try {
          SpeechToText service = new SpeechToText();
          service.setUsernameAndPassword("<username>", "<password>");
          System.out.println(service.getModels());
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
    
    thread.start();
    
  7. Start the simulator and look at the console. You should see a message like

    I/CredentialUtils: JNDI string lookups is not available.
    

    and the Speech to Text model list.

    I/System.out: [{
    I/System.out:   "name": "en-US_NarrowbandModel",
    I/System.out:   "rate": 8000
    I/System.out: }, {
    I/System.out:   "name": "pt-BR_BroadbandModel",
    I/System.out:   "rate": 16000
    I/System.out: }, {
    I/System.out: .... more models here
    I/System.out: }, {
    I/System.out:   "name": "en-US_BroadbandModel",
    I/System.out:   "rate": 16000
    I/System.out: }]
    


来源:https://stackoverflow.com/questions/36217233/javax-content-not-accessible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!