Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Am new to java .getJSONValue method returns a array like this [men,women] and [dog,cat] while executing the above code am getting:

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map

  private Map<String, List<String>> devcap = new HashMap <String, List<String>>();
     public <T>T getJSONValue(Response res, String path ){
           String json = res.asString();
           JsonPath jpath = new JsonPath(json);
           return jpath.get(path);
     }



     devcap = helper.getJSONValue(response, "results.devices.cap");
     try {    
       for (Map.Entry<String, List<String>> entry : devcap.entrySet()) {
            String key = entry.getKey();
            List<String> values = entry.getValue();
            System.out.println("Key = " + key);
            System.out.println("Values = " + values + "n");
       }

How to get rid of this error

share|improve this question
    
You need to iterate the ArrayList to convert it to a Map. stackoverflow.com/questions/7789527/… – Shawn Jacobson May 12 '15 at 3:43
    
You're trying to treat something as a map, that is actually a list. You can get rid of this error by treating it like what it is: a list. So List<Something> devcap instead of Map<Something> devcap – Erwin Bolwidt May 12 '15 at 3:46
    
how it can be done in my case.?coz am new to java – saathu May 12 '15 at 3:46
    
i changes it as ` private List<HashMap<String, List<String>>> devcap = new ArrayList<HashMap<String,List<String>>>();` – saathu May 12 '15 at 3:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.