从Android连接到IBM Watson对话API时出现未知的模式字符'X'异常 [英] Unknown pattern character 'X' Exception occurs connecting to IBM Watson conversation API from Android

查看:73
本文介绍了从Android连接到IBM Watson对话API时出现未知的模式字符'X'异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android上的一些聊天机器人应用程序.之前一切都很好.但是以前使用过的相同应用程序现在显示错误. 未知模式字符'X'".不知道我做错了什么.我做了很多尝试来发现错误,但是失败了.我在这里附上我的代码.

I am working with some chat bot application on Android. Everything was working perfect before. But the same application that worked before, now shows an error. "Unknown pattern character 'X' " . Don't know what i did wrong. I tried a lot to find the bug but failed. I am attaching my code here..

package com.example.rove2.conversation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.ibm.watson.developer_cloud.conversation.v1.ConversationService;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageRequest;
import com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {
String conversation_username;
String  conversation_password;
String workspace_id;
Button sendbtn,clearbtn,jsonbtn;
EditText input,json;
String JsonString="";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    conversation_username = "c9d2fd27-0868-4e56-b3ae-66b76d2b52b4";
    conversation_password = "DYLntDWRvf12";
    workspace_id="cbb7fc4d-c216-4a81-ae70-445d6fa9dab9";
    sendbtn=(Button)findViewById(R.id.button);
    clearbtn=(Button)findViewById(R.id.button2);
    input = (EditText)findViewById(R.id.editText);
    json =(EditText)findViewById(R.id.editText2);
    jsonbtn=(Button)findViewById(R.id.button3);
}
String sendtoWatson(String message)
{
    ConversationService service = new 
ConversationService(ConversationService.VERSION_DATE_2017_02_03);
    service.setUsernameAndPassword(conversation_username, 
conversation_password);
    MessageRequest newMessage = new 
MessageRequest.Builder().inputText(message).build();
    MessageResponse response = service.message(workspace_id, 
newMessage).execute();
    String tx = response.toString();
    return  tx;
}
public void send(View view){
    Thread t=new Thread(){
        public void run() {
            String text = input.getText().toString();
            final String result = sendtoWatson(text);
            JsonString = result;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try{
                        JSONObject reader = new JSONObject(result);
                        JSONObject output = reader.getJSONObject("output");
                        JSONArray Intent = output.getJSONArray("text");
                        String speechTxt=Intent.getString(0);
                        json.setText(speechTxt);

                    }
                    catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
        }};
    t.start();
}
public void clearbutn(View view){
    input.setText("");
    json.setText("");
}
public void jsonbtn(View view){
    json.setText(JsonString);
}
}

该错误发生在该行

MessageResponse response=service.message(workspace_id,newMessage).execute();

我可以在此处 Android应用程序的BlueMix服务错误-'未知模式字符'X' 但是我无法理解该解决方案,我的android studio版本是2.1.2,而JDK版本是8.请帮助...

I could find an answer for a similar issue here BlueMix service error with Android app - 'Unknown pattern character 'X'' But i am not able to understand the solution my android studio version is 2.1.2 and JDK version is 8. Please help...

推荐答案

这是已解决的已知问题,但尚未发布给maven.如果您查看存储库中的README,则有有关在等待3.8.1时如何使用快照发行版的说明.

This is a known issue that was fixed But not released to maven yet. If you look at the README in the repository, there are instructions on how to use the snapshot release while we wait for 3.8.1.

这篇关于从Android连接到IBM Watson对话API时出现未知的模式字符'X'异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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