I'm using Eclipse on a Windows 7 64x machine. I've researched this problem and found many have had a similar one, but no solution I came across quite worked for me.
I'm working on a Project named Assignment_1
, on a class named Percolation
. I'd like to use the object WeightedQuickUnionUF
which is inside a package contained within a jar file, named algs4.jar
.
I seem to have added the Jar file I'm interested in to the build-path (it now appears under "Referenced Libraries"). The jar file algs4.jar
resides in a folder named lib
inside my project's folder.
However, when I try to declare an object of type WeightedQuickUnionUF
inside my class, I get an error "WeightedQuickUnionUF
cannot be resolved to a type".
I tried various import
commands (including just import WeightedQuickUnionUF
)before the class declaration and all of them yield the error "The import so and so
cannot be resolved".
For example, this piece of code yields both of these errors. One at the import
line, and another at the declaration of the WeightedQuickUnionUF
object:
package assignment_1_package;
import algs4.WeightedQuickUnionUF;
public class Percolation {
private int[][] grid;
public int gridDimension;
private int opensGrid[][];
private WeightedQuickUnionUF model;
... //rest of class body here
This has baffled me for an entire day and I can't seem to figure this out. Thanks for your efforts.
Edit: here is a link to the class I wish to import: http://algs4.cs.princeton.edu/15uf/WeightedQuickUnionUF.java.html