views:

54

answers:

3

I have a java project in which I have "Referenced Libraries". In the "Referenced Libraries" I have a .jar file of a library that I use (I use only one external library).

When I try to "Run -> Run" the code I have a NullPointerException. From my previous experience I know that it it (very likely) because my code does not see the library.

I just started to use Eclipse and it can be the I do not "connect" libraries in a correct way. Should I use some options or additional action to force Eclipse to see the .jar file of the library?

ADDED:

By the right click on the library I get a drop-down menu in which I see "Build Path". My be I need to do something there?

+1  A: 

Have you tried this? http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29

Add the library's to your build path :]

Bas
According to the information on the given page, my .jar file seems to be added to the build path.
Roman
+1  A: 

External JARs should be added with Java Build Path -> Libraries -> Add External JARs.

Generally the lack of wavy red lines under your class references will tell you Eclipse has recognised the JAR ok.

Depending on your target type (you don't say) there may be additional steps to deploy the JAR.

Many things can cause a NullPointerException. It would be useful to see the full error and callstack. In my experience, missing library content manifests as ClassNotFoundExceptions.

Jim Blackler
A: 

Are you sure it's the missing Jar?

NullPointerException will not usually happen if you have a missing jar For that you may get a ClassNotFoundException or MethodNotFoundException

Adding a breakpoint for NullPointerException in eclipse will tell you when it happened

Ehrann Mehdan