从Android连接到IBM Watson对话API时发生java未知模式字符“X”异常
我正在Android上使用聊天机器人应用程序。以前一切都很好。但是以前工作的应用程序现在显示错误。未知模式字符“X”。不知道我做错了什么。我尝试了很多来找到这个bug,但是失败了。我在这里附上我的代码
package com.example.rove2.conversation;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.os.Bundle;
import 安卓.view.View;
import 安卓.widget.Button;
import 安卓.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();
我可以在这里找到类似问题的答案BlueMix service error with Android app - 'Unknown pattern character 'X'' 但是我无法理解我的安卓 studio版本是2.1.2,JDK版本是8。请帮忙
# 1 楼答案
这是一个已知的问题,已修复,但尚未发布给maven。如果您查看存储库中的自述文件,那么在我们等待
3.8.1
时,会有一些关于如何使用快照版本的说明