I am writing a program that inputs data and creates a graph represented by two adjacency matricies. One matricie contains one weight, and the other a different weight, ie distance and time between nodes. I am recieving the Double cannot be cast to Integer at a point where no Doubles are even involved let alone casting. I am very confused by this error. Here is my code:
public static void main(String args[]){
ArrayList<Integer> node1 = new ArrayList();
ArrayList<Integer> node2 = new ArrayList();
ArrayList<Integer> time = new ArrayList();
ArrayList<Double> distance = new ArrayList();
String file = "distanceAndTime.dat";
// Input data from file to ArrayLists
inputData(file, node1, node2, time, distance);
int numNodes = howManyNodes(node1,node2);// get number of distinct nodes
graph g = new graph(numNodes); // create graph of correct size
//Label all nodes
for(int j = 0; j<numNodes; j++){
g.setLabel(j, "v"+j);
}
// add edge w/time weight
for(int i=0; i<node1.size(); i++){
g.addTimeEdge(node1.get(i), node2.get(i), time.get(i)); //This is where error occurs
}
/*
// add edge w/distance weight
for(int i=0; i<node1.size(); i++){
g.addDistanceEdge(node1.get(i).intValue(), node2.get(i).intValue(), distance.get(i).doubleValue());
}*/
g.printTime();
g.printDistance();
}
public class graph {
private int[][] timeEdge; // adjacency matrix w/time traveled node to node
private double[][] distanceEdge; // adjacency matrix w/distance between nodes
private Object[] labels;
public graph(int n) {
timeEdge = new int [n][n];
distanceEdge = new double[n][n];
labels = new Object[n];
}
public int size(){
return labels.length;
}
public void setLabel(int vertex, Object label){
labels[vertex]=label;
}
public Object getLabel(int vertex){
return labels[vertex];
}
public void addTimeEdge(int source, int target, int w){
timeEdge[source][target] = w;
}
public void addDistanceEdge(int source, int target, double w){
distanceEdge[source][target] = w;
}
...
Thanks to anyone that can help me with this error.