I'm trying to run a program I have made in Java, but I don't know what is happening that it is giving me the following error:
Exception in thread "main" java.lang.ClassCastException:
java.lang.String cannot be cast to java.util.ArrayList
Here is the code:
public static ArrayList connections(ArrayList list3) {
ArrayList connections = new ArrayList();
int row1 = 1;
int row2 = 0;
int col = 0;
connections.add(new ArrayList());
((ArrayList)connections.get(0)).add(0);
((ArrayList)connections.get(0)).add(1);
System.out.print(((ArrayList)connections.get(0)).get(0));
while(row1 < list3.size()) {
if(((ArrayList)list3.get(row1)).get(col).equals(((ArrayList)connections.get(row2)).get(col))){
connections.add(((ArrayList)list3.get(row1)).get(1));
row1++;
}
else {
connections.add(new ArrayList());
connections.add(((ArrayList)list3.get(row1)).get(0));
row2 = row1;
row1++;
}
}
return connections;
}
It seems that the error is in the if statement. Can somebody help me with this?