Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use classes in Referenced Libraries in Eclipse

Tags:

java

eclipse

I have imported the algs4.jar file as a referenced library as seen above. All seems to be fine but I can't seem to use or access any of the classes in the library.

Is there an import statement I'm missing?

Image reference:

Note how I'm trying to use BinarySearch from the referenced library but it is not offering me an option to use or import it.

like image 265
jeffstern Avatar asked Aug 12 '12 18:08

jeffstern


1 Answers

I am taking an Algorithms class via Coursera that utilizes the algs4.jar reference library.

The Problem:

The issue you are having is that the reference library is located in the default package and the source in which you are accessing the reference library is not.

The Solution

All classes in your project need to be in the default package, otherwise the reference libraries (which are located in the default package) will not be recognized. Your project classes need to be in the src directory and you should not declare a package at the beginning of your .java files. Additionally you also need to make sure you've added the reference libraries to your build path.

like image 164
Kristin Peterson Avatar answered Oct 24 '22 23:10

Kristin Peterson