ClassCastException : cant be cast to java.lang.Integer

前端 未结 4 666
谎友^
谎友^ 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:51

    the error lies here

      public void addEdgeForIndexing(int from, int to, int T) throws IllegalArgumentException, IllegalAccessException {   
    
                Edge e = new Edge(from,to,T);
                nodeIDs.add(e.from);
                nodeIDs.add(e.to);
    
                ArrayList tmp = null;
                if (edges.containsKey(e.from))
                  tmp = (ArrayList) edges.get(e.from);
                else {
                  tmp = new ArrayList();
                  edges.put(e.from,tmp);
                }
                tmp.add(e);//adding an edge to tmp
    

    later in the code you get the ArrayList out of the Map as ArrayList but it an ArrayList containing Edge try to change

    tmp = new ArrayList();
    

    to

    tmp = new ArrayList();
    

    you should get a compilation error when adding an Edge to it

提交回复
热议问题