我試着在Android中創建一個應用程序chatbot。我使用Pandorabots作爲Chatbot服務器。 Device Android與服務器之間的連接。我使用pandorabot XML-RPC API,並使用android-xmlrpc中的xml-rpc庫。所以這個我的代碼:XML-RPC錯誤,org.xmlpull.v1.XmlPullParserException
public class MainActivity extends Activity {
private EditText editOne;
private TextView textOne;
private Button ButtonOne;
private XMLRPCClient server;
private URI uri;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
uri = URI.create("http://www.pandorabots.com/pandora/talk-xml?botid=e80e92407e341007");
server = new XMLRPCClient(uri);
editOne = (EditText) findViewById(R.id.editText1);
textOne = (TextView) findViewById(R.id.textView1);
ButtonOne = (Button) findViewById(R.id.button1);
textSatu.setText(getDataMethod("hi"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private String getDataMethod(String num) {
String text = "";
try {
Log.w("Running server.call", "prosess");
Object[] data = (Object[]) server.call("input", num);
Log.w("server.call Run", "finish");
Log.w("Run HashMap", "prosess");
for(Object o: data) {
HashMap map = (HashMap) o;
Log.w("HashMap Berjalan", "Error");
text = text + "'that' => " + map.get("that") + "\n\n";
}
} catch (XMLRPCException e) {
Log.w("XMLRPC Test", "Error", e);
text = "XMLRPC error";
}
return text;
}
}
但我得到錯誤。這就是說:org.xmlpull.v1.XmlPullParserException:expected:START_TAG {null} methodResponse(position:START_TAG @ 1:45 in [email protected])
任何人都可以幫助我嗎?請。
後的XML,請。編輯:沒關係,我看到它。 –
對不起。我沒有明白你的意思。你的意思是在這裏http://www.pandorabots.com/pandora/talk-xml?botid=e80e92407e341007&input=hi? –
我幾乎認爲你錯誤地使用了'XMLRPCClient',但我無法分辨,因爲我找不到任何文檔。 –