简体   繁体   中英

Use HashMap in XMLRPC result

I am new in Android development, and I am trying to receive a HashMap in RESULT by using XMLRPC but every time it's crash the application, this is my code please advice me :

  Object RESULT =  XMLRPCClient.callEx(methodname,new Object[] {params});
         Map FRESULT= (Map) RESULT; 

I have been dealing with this also and managed to get the values this way:

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);
}

I'm sure it's a mess, I'm noob in Java myself, but it worked for me. Hope it helps :)

Now the Application pass this peacefully after implementing :

 Object RESULT = XmlRpcConnect.ServerCall_a(method,new Object[] {params});
          Map<String, Object> FRESULT= (HashMap<String, Object>) RESULT;

with some changes in my XmlRpcConnect Class:

@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;
                                }

but when trying to extract the values it's crash again , any advice :

              if (FRESULT.get("status") == null) {
                          result = (String) FRESULT.get("status");
                          toastDialog(result);
               }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM