ClassCastException : cant be cast to java.lang.Integer

前端 未结 4 660
谎友^
谎友^ 2021-01-07 14:20

I know this has been asked a lot in stackoverflow but I could not find answers that work to my problem.

In the following code below, I cant print out each item in

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-07 14:59

        public ArrayList getOutEdgesToP(int id) {
    if (!edges.containsKey(id)) {
        return null;
    }
    System.out.println(edges.get(id));
    ArrayList a = edges.get(id);
    System.out.println("Arraylist a: " + a); // if i print using this its
                         // okay. but i cant get each
                         // item in this ArrayList like
                         // below
    for (Object item : a) { // the error of classcastexception is here
        System.out.println(item);
    }
    
    return a;
    }
    

    This should work. I don't have a lot of time to search for an explanation.

提交回复
热议问题