Javax内容不可访问 [英] Javax content not accessible

查看:121
本文介绍了Javax内容不可访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于要导入此程序包,我可以使用Watson Services,因此在尝试运行android应用程序时出现运行时错误.

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

,相应的堆栈跟踪为:

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

我一直在寻找此错误的真正问题,发现在出现错误的文件"CredentialUtils.java"中,无法识别这三个输入(无法解析符号):

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;

我使用Android Studio和最新版本的jdk(1.8.0.77).这些Java文件存在,我可以看到它们,但由于某些原因无法访问:无法导入javax.naming中的每个文件(以及其他文件夹).

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.

我该如何解决这个问题?我尝试导入一个包含javax.naming类的.jar文件,但无法正常工作.有没有办法使这些类可见?

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!

推荐答案

我认为您使用的版本早于2.7.1.我无法重现您的问题,因此尝试使用其他配置,包括您的配置. 确保清理工作区并获取库的最新版本. 在您的build.gradle中,您应该拥有:

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'

这是提交,可解决您的问题.该修补程序以2.7.1版本发布.

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:

在Android中使用Watson API的步骤,您应该:

  1. 下载并安装Android Studio
  2. 打开Android Studio
  3. File > New > New Project.
  4. 选择一个名称,然后单击nextnextnextFinish
  5. <project-name>/app/build.gradle中添加:

  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'  

  • MainActiviy.java末尾的MainActiviy.java中添加:

  • 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();
    

  • 启动模拟器并查看控制台.您应该会看到类似

  • 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: }]
    

  • 这篇关于Javax内容不可访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆