Please post the full text of the error message.
What line in the code has the error?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Can you post complete code that will compile, execute and show the problem?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Maybe a Double is sneaking into your incorrectly initialised ArrayLists - can we see the code for the inputData method?
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
I get 10 warnings when I compile the code. I bet if you fix the code so there are no warnings it will fix your problem.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
This is a classic example of why you should use classes rather than parallel arrays .
(spoiler follows)
inputData(file, node1, node2, time, distance);
public static void inputData(String fileName, ArrayList n1, ArrayList n2, ArrayList d, ArrayList t)
... and that's how you get Double values in the time array.
If you had initialised your ArryLists properly and declared the parameters fully for the method you would have found this error immediatley.
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
new ArrayList(); // an arraylist that accepts any kind of data
new ArrayList<Integer>(); // an arraylist for Integers only
new ArrayList<>(); // short version (needs Java 7)
similarly:
public static void inputData(String fileName, ArrayList<Integer> n1 ...
// prevents you passing an ArrayList<Double> as parameter
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
Do you have warnings turned on for the compiler? It will flag all the places where the code needs to be fixed.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
That's a lot better - the compiler has a much better chance of picking up any mistakes. Best of all is to have a class rather than those parallel arrays:
class Edge {
public final int node1, node2, time; // I assume it's immutable
public final double distance;
public Edge (int node1, int node2.....
this.node1 = node1;
.....
Then when you read the file create new Edge objects and add them to an ArrayList<Edge>
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33