我是Android开发的新手,我正在尝试使用XMLRPC在RESULT中接收HashMap,但每次崩溃应用程序时,这都是我的代码,请指教我:
Object RESULT = XMLRPCClient.callEx(methodname,new Object[] {params});
Map FRESULT= (Map) RESULT;
答案 0 :(得分:2)
我一直在处理这个问题,并设法以这种方式获得价值:
try {
Object[] answer = (Object[]) client.call("call", sessionId, method, params);
HashMap map = (HashMap) answer[0]; // get first item of the response because in my case the response was an array of Objects with one item in it holding the HashMap
Object[] records = (Object[]) map.get("records"); // I only needed values from "records" key
for (int i = 0; i < records.length; i++) {
HashMap record = (HashMap) records[i]; // create another map from the records values, in my case uid's of categories
Category cat = new Category(); // creating new instance of my Category class
cat.setCatUid((String) record.get("uid")); // calling a method of the Category class to set Uid to the value from record HashMap
m_categories.add(cat); // this adds it to my ArrayList<Category>
}
} catch (XMLRPCException e) {
Log.e(method, "Exception", e);
}
我确定它一团糟,我自己也是Java的noob,但它对我有用。希望它有所帮助:)
答案 1 :(得分:0)
现在,应用程序在实施后平静地传递了这个:
Object RESULT = XmlRpcConnect.ServerCall_a(method,new Object[] {params});
Map<String, Object> FRESULT= (HashMap<String, Object>) RESULT;
我的XmlRpcConnect类中有一些更改:
@SuppressWarnings("unchecked");
public static Object ServerCall_a(String method, Object[] params){
XMLRPCClient client = new XMLRPCClient(server);
HashMap<String, Object> result=null;
try{
result = (HashMap<String, Object>) client.callEx(method, params);
}
catch(XMLRPCFault f){
// result = ("Fault message: " + f.getMessage());
}
catch(XMLRPCException e){
// result = ("Exception message: " + e.getMessage());
}
return result;
}
但是当尝试提取值时,它会再次崩溃,任何建议:
if (FRESULT.get("status") == null) {
result = (String) FRESULT.get("status");
toastDialog(result);
}