I'm trying create something like this tutorial on creating a graph and I'm coming across an error: Exception in thread "main" java.lang.ClassCastException: proj.Car cannot be cast to java.lang.Comparable
.
Car class
Integer id;
String model;
String brand;
float price;
Cars class (both have been instantiated already):
TreeMap<Integer, Car> m;
TreeMap<Car, LinkedList<Car>> adjList;
Main:
for(Map.Entry<Integer, Car> entry : a.m.entrySet()){
Car val = entry.getValue();
LinkedList<Car> list = new LinkedList<Car>();
a.adjList.put(val, list);
}
This creates an adjList
for every Car object in m
but the problem is the error. I've tried making sure the entered variables are of the same type by using instanceof
and it returns true. So i'm not sure where the error comes from.