I am working on a program to implement Kruskal's algorithm on a minimum spanning tree. I have this as my main method inside my Kruskal.java file.
public static void main(String[] args) {
In in;
in = new In(args[0]);
EdgeWeightedGraph G = new EdgeWeightedGraph(in);
Kruskal mst = new Kruskal(G);
for (Edge e : mst.edges()) {
StdOut.println(e);
}
StdOut.printf("%.5f\n", mst.weight());
}
The problem I am having is when I try to run the program, I receive an array out of bounds exception. The exception originates from the
in = new In(args[0]);
line. I know that an array out of bounds exception occurs when, in simplified terms, when the program tries to load more items into the array than it has space for. This ultimately causes it to go "out of bounds". In the main method below, EdgeWeightGraph references another class in the program, EdgeWeightGraph.java. I believe it is being populated from the EdgeWeightedGraph class but I am not entirely sure. Any advice on how to fix this array out of bounds exception?
EDIT: Here is a link to the In.java file that I am using: http://algs4.cs.princeton.edu/12oop/In.java.html and here is my Kruskal class that the code from above comes from http://algs4.cs.princeton.edu/43mst/KruskalMST.java.html